couchdbkit icon indicating copy to clipboard operation
couchdbkit copied to clipboard

DocumentSchema inside a Document instance.

Open janua opened this issue 14 years ago • 4 comments

This may have something to do with the clone issue.

>>> from couchdbkit import *
>>> class Address(DocumentSchema):
...     address = StringProperty()
...     
>>> class Person(Document):
...     name = StringProperty()
...     address = SchemaProperty(Address())
...     
>>> p = Person()
>>> p.name = 'XXX'
>>> p.address.address = 'XXX ADDRESS'
>>> p.name
u'XXX'
>>> p.address.address
u'XXX ADDRESS'
>>> p2 = Person()
>>> p2.address.address
u'XXX ADDRESS'
>>> p2.name

As you can see, because I am declaring Address() in the constructor of SchemaProperty, any new instances always point to the same object. I have tried to get around this by trying to make a new Address object in init, but I cannot seem to get it to work.

janua avatar Jun 02 '11 11:06 janua

If you look here, I have used how it is used in the documentation. But I have realised you don't need to initialise the Address object in the SchemaProperty constructor. Instead just take out the (), making it a reference to the class type instead of an instance.

This seems to fix it but can other people to check just to make sure? Thanks

janua avatar Jun 15 '11 12:06 janua

It was at first a feature. Maybe raising it on the ml for a discussion ?

benoitc avatar Jun 20 '11 09:06 benoitc

Well I now have no problems with it when using without initialising, if you see in my comment.

janua avatar Jun 20 '11 11:06 janua

well i'm not sure what you mean. Can you provide a short test about what do you expect and what is coming? Thanks!

benoitc avatar Sep 19 '11 16:09 benoitc