couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Markus Jelsma <>
Subject Re: Tips for many to many
Date Thu, 11 Feb 2010 13:18:46 GMT

You can explicitely list the relations for each entity in its own document, 
negating the need for a link-table.

 _id : channel_x1
 type : channel
 lineups : [lineup_y1, lineup_y2]

Now you have a channel document pointing to 0-n lineups. Obviously, for 
lineups you'll do it the other way around!

 _id : lineup_y1
 type : lineup
 lineups : [channel_x1, channel_x2]

An other possibility is embedding all related data in a master document, but 
that may be hard to handle depending on your use case.


>If I have a true many to many relationship that doesn't normalize easily,
>what are some guidelines to make it couch-friendly?
>I've found that couch does a great job with one-to-many or one-to-one
>relationship. It's easy to write a view that will return all the comments
>for a given post, for example.
>But what about many-to-many? For example, I'm working with TV Guide data.
>There are lineups and channels. A lineup can have a lot of channels, but the
>channels can belong to several lineups. I then need to get what is playing
>at 2:00 on every channel in my lineup.

Markus Jelsma - Technisch Architect - Buyways BV
050-8536620 / 06-50258350

View raw message