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: * http://127.0.0.1:3000/books.xml * http://127.0.0.1:3000/owners.xml 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: * http://127.0.0.1:3000/books/3/owners.xml (lists all owners of book 3) * http://127.0.0.1:3000/owners/7/books.xml (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, http://127.0.0.1:3000/owners/7/books.xml 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 :-) Thanks, Mike --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I have a same problem :) On Jul 4, 6:55 pm, SingleShot <mike.whittem...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m having trouble setting upnestedresourcesis 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: > *http://127.0.0.1:3000/books.xml > *http://127.0.0.1:3000/owners.xml > > 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 fornestedresources"). I''d like the URLs to look something like this: > *http://127.0.0.1:3000/books/3/owners.xml (lists all owners of book > 3) > *http://127.0.0.1:3000/owners/7/books.xml (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,http://127.0.0.1:3000/owners/7/books.xmlmight 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 :-) > > Thanks, > > Mike--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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: http://railscasts.com/episodes/47-two-many-to-many Good luck, -Conrad On Mon, Aug 25, 2008 at 3:58 AM, Dmitrij Smalko <dsmalko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I have a same problem :) > > On Jul 4, 6:55 pm, SingleShot <mike.whittem...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I''m having trouble setting upnestedresourcesis 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: > > *http://127.0.0.1:3000/books.xml > > *http://127.0.0.1:3000/owners.xml > > > > 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 > fornestedresources"). I''d like the URLs to look something like this: > > *http://127.0.0.1:3000/books/3/owners.xml (lists all owners of book > > 3) > > *http://127.0.0.1:3000/owners/7/books.xml (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, > http://127.0.0.1:3000/owners/7/books.xmlmight 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 :-) > > > > Thanks, > > > > Mike > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---