couchdb-python icon indicating copy to clipboard operation
couchdb-python copied to clipboard

Feature: Document model referencing

Open djc opened this issue 10 years ago • 1 comments

From kxepal on August 05, 2010 20:20:18

Feature discussion and description: http://groups.google.ru/group/couchdb-python/browse_thread/thread/9276b4aad7845bd9?hl=ru Usage example: class Author(Document): name = TextField()

class Post(Document): author = DocumentRefField(Author)

post = Post() post.author(id='Mike') post.author.name = 'Mike'

-- or --

post.author = Author(id='Jan', name='Jan')

loading document with all references:

post = Post.load(db, post_id, recursive=True)

storing document and all referenced ones:

post.store(db, recursive=True)

new feature - in place reloading:

post.author.reload(db) # so we get latest version of referenced document

if we dont wants to resolve all references now, but later - yes:

post = Post.load(db) assert post.author.name is None post.author.resolve(db) assert post.author.name is not None

Feature is quite alpha, but it works(: I'll use it in my own projects, because I very need it, so this is not final state of patch.

Attachment: docref.patch docref_tests.patch

Original issue: http://code.google.com/p/couchdb-python/issues/detail?id=145

djc avatar Jul 12 '14 14:07 djc

From kxepal on February 12, 2011 11:13:53

Time had showed that this way is really buggy and requires to change a lot of code to made it works fair stable. I'll have to try to find another way.

djc avatar Jul 12 '14 14:07 djc