You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Sean Clark Hess <se...@gmail.com> on 2010/02/11 05:26:03 UTC
Tips for many to many
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.
Thanks
Re: Tips for many to many
Posted by Markus Jelsma <ma...@buyways.nl>.
Hi,
You can explicitely list the relations for each entity in its own document,
negating the need for a link-table.
doc{
_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!
doc{
_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.
Cheers,
>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.
>
>Thanks
Markus Jelsma - Technisch Architect - Buyways BV
http://www.linkedin.com/in/markus17
050-8536620 / 06-50258350