Symmetrical Routes for Nested Resources

I'm having trouble setting up nested resources is a certain way that I
believe makes sense.

Given rules like these:
* an owner owns many books
* a book can be owned by many owners
* an owner can own multiple copies of the same book

I have a many-to-many relationship of Owners-to-Books with the "link"
table (we'll call it "Ownerships" since I can't think of a nice name)
having an attribute for tracking the number of copies of a book an
owner owns.

I have no problem listing all books, or listing all owners:

What I can't figure out is how to set up my routes/controllers to list
all books owned by a particular owner, and all owners that own a
particular book (i.e. what I call "symmetrical routes for nested
resources"). I'd like the URLs to look something like this:
* (lists all owners of book
* (lists all books owned by
owner 7)

What's extra tricky is that I want the listings to also contain the
number of copies from the "link" table. So, for example, might return the equivalent
of this as XML:

To Kill A MockingBird, 2
The Zombie Survival Guide, 1
War and Peace, 4

Please help this noob :slight_smile:



I have a same problem :slight_smile:

Hi, you might want to consider using a join model when you have a many to many. Ryan Bates covers this very nicely in his screencast that can be found here:

Good luck,