peritor / simply_stored

A convenience wrapper around CouchDB (using CouchPotato) that supports relations and S3 attachments
Other
140 stars 16 forks source link

linked documents feature (feature request) #6

Open kolosy opened 14 years ago

kolosy commented 14 years ago

since .11, couchdb supports the notion of linked documents (emitting _id). it would be beneficial if the default views would leverage this to fetch associated documents

jweiss commented 14 years ago

I'm not sure how you would use it. We use the views to load associations on demand, e.g.

user.comments

will load all comment objects and

comment.user

will load the user to this comment. IMHO using the _id feature would allow you to load the user while you are loading the comment, similar to the :include feature of ActiveRecord. But this would only work for objects that use "belongs_to" to load the master object too.

Am I missing something?

kolosy commented 14 years ago

it's the on-demand that's both good and bad. it's good in scenarios where you don't frequently need it, but costly if you're displaying a list. picture a person with an address. if i load a list of people, and then display their home addresses, a list of n people will result in n+1 calls to the server. given the option to say "eager-load the belongs_to", that can come back down to 1.

jweiss commented 14 years ago

Yes, but it only works for the belongs_to, so in your example probably the person has_one address and the address belongs_to a person. If you display a list of persons this wouldn't work, only if you display a list of addresses.

The real solution is to have a custom view or even store the address on the person.

But I can see how much trouble it would to add it to blongs_to. I'm only afraid that it will confuse people as it only works for belongs_to and not has_one/many as it does in SQL.

CouchDB is different :-)

kolosy commented 14 years ago

yeah - i got it backwards, but the scenario still holds