I''ve searched alot tonight for this answer, it must be out there, so thanks for any help. I have a simple setup like so: LIST has_many :list_items has_many :business, :through => :list_items LIST_ITEM belongs_to :list belongs_to :business BUSINESS belongs_to :list_items ...? So I have busineses on my website. Now I''ve made some lists, that have list items (which are businesses). 1. Is belongs_to list_items ok for my model above? 2. If i''m in the business controller viewing a business, how can i see what lists that business is listed in? So in my view in business, i want to show ''this business is listed in list X, list Y, etc.''. Thanks for any help! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi -- On Thu, 13 Mar 2008, Dankinit wrote:> > I''ve searched alot tonight for this answer, it must be out there, so > thanks for any help. > > I have a simple setup like so: > > LIST > has_many :list_items > has_many :business, :through => :list_itemsPlural: has_many :businesses, etc.> LIST_ITEM > belongs_to :list > belongs_to :business > > BUSINESS > belongs_to :list_items ...?That should be has_many :list_items. I think you''ll also want has_many :lists, :through => :list_items> > So I have busineses on my website. Now I''ve made some lists, that > have list items (which are businesses). > > 1. Is belongs_to list_items ok for my model above?No -- see above.> 2. If i''m in the business controller viewing a business, how can i > see what lists that business is listed in? So in my view in business, > i want to show ''this business is listed in list X, list Y, etc.''.If you have a business object in the variable @business, and if you do has_many :lists as above, then you can do: @business.lists and that will give you a collection (array) of all the lists. I kind of think that maybe you want businesses to have lists and to have list_items through lists, rather than the other way around, but I''m not sure. Anyway, you can follow the patterns here. The goal is to make it easy to get the information from the objects you''ve got. David> Thanks for any help! > >-- Upcoming Rails training from David A. Black and Ruby Power and Light: ADVANCING WITH RAILS, April 14-17 2008, New York City CORE RAILS, June 24-27 2008, London (Skills Matter) See http://www.rubypal.com for details. Berlin dates coming soon! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thank you so much David, it all worked perfectly! Much appreciated! Dan On Mar 13, 11:17 pm, "David A. Black" <dbl...-0o/XNnkTkwhBDgjK7y7TUQ@public.gmane.org> wrote:> Hi -- > > On Thu, 13 Mar 2008, Dankinit wrote: > > > I''ve searched alot tonight for this answer, it must be out there, so > > thanks for any help. > > > I have a simple setup like so: > > > LIST > > has_many :list_items > > has_many :business, :through => :list_items > > Plural: has_many :businesses, etc. > > > LIST_ITEM > > belongs_to :list > > belongs_to :business > > > BUSINESS > > belongs_to :list_items ...? > > That should be has_many :list_items. I think you''ll also want > has_many :lists, :through => :list_items > > > > > So I have busineses on my website. Now I''ve made some lists, that > > have list items (which are businesses). > > > 1. Is belongs_to list_items ok for my model above? > > No -- see above. > > > 2. If i''m in the business controller viewing a business, how can i > > see what lists that business is listed in? So in my view in business, > > i want to show ''this business is listed in list X, list Y, etc.''. > > If you have a business object in the variable @business, and if you do > has_many :lists as above, then you can do: > > -z2zUxyb0RMfT9nyZL6hAQg@public.gmane.org > > and that will give you a collection (array) of all the lists. > > I kind of think that maybe you want businesses to have lists and to > have list_items through lists, rather than the other way around, but > I''m not sure. Anyway, you can follow the patterns here. The goal is to > make it easy to get the information from the objects you''ve got. > > David > > > Thanks for any help! > > -- > Upcoming Rails training from David A. Black and Ruby Power and Light: > ADVANCING WITH RAILS, April 14-17 2008, New York City > CORE RAILS, June 24-27 2008, London (Skills Matter) > Seehttp://www.rubypal.comfor details. Berlin dates coming soon!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---