couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Uvarov <alexander.uva...@gmail.com>
Subject Re: How to make equivalent of WHERE on JOINed table in CouchDB?
Date Sat, 12 Dec 2009 21:58:01 GMT
If I right understand your question:

Look at git commit 926af4ba11093dcaff13bea0e4ed9addfc67ab10
"include_docs now take an _id (as well as a _rev) in the emitted  
value, to load docs other than the one doing the emitting. This means  
you can have one doc list a
set of other docs to load in a single query. Enjoy!"

function(doc) {
   if (doc.type == "Car") {
     emit(doc.brand, null); // emits car document
     emit(doc.brand, { _id: doc.person_id }); // emits whole person  
document
   }
}

Then query your view using include_docs=true, key=Ferrari and you will  
get both Car and Person in a single query.

On Dec 13, 2009, at 1:38 AM, Paweł Stawicki wrote:

> Crossposting from stackoverflow.com.
>
> Assume we have two kind of documents in CouchDB. Person and Car:
>
> Person:
> _id
> firstname
> surname
> position
> salary
>
> Car:
> _id
> person_id
> reg_number
> brand
> So there is one to many relationship. One person can have many cars.
>
> I can construct map function to get every person and his/her car next
> to each other. In such case key is array [person.id, 0] and
> [car.person_id, 1].
>
> What I can't do, is limiting this view to owners of specific brand
> only, e.g. if I need salaries of owners of Ferrari. So set of
> documents (persons) is limited by related documents (cars). How can I
> do it?
>
> Best regards
> --
> Paweł Stawicki
> http://pawelstawicki.blogspot.com
> http://szczecin.jug.pl
> http://www.java4people.com


Mime
View raw message