Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

linked documents feature (feature request) #6

kolosy opened this Issue Sep 22, 2010 · 4 comments


None yet
2 participants

kolosy commented Sep 22, 2010

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 Sep 22, 2010

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


will load all comment objects and


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 Sep 22, 2010

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 Sep 23, 2010

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 Sep 25, 2010

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment