I am new to rails and stuck on one Querying issue. Here is the situation. Model: Category class Category < ActiveRecord::Base has_and_belongs_to_many :postings has_and_belongs_to_many :volunteers end Model: Posting class Posting < ActiveRecord::Base has_and_belongs_to_many :categories end Model: Volunteer class Volunteer < ActiveRecord::Base has_and_belongs_to_many :categories end ------- Now Here is the problem I am trying to solve I want to find out all the postings of the categories that the volunteer is interested in. The volunteer might be interested in more than one categories and posting might be assigned more than one categories. Here is the basic pseudocode vol=Volunteer.find 1 vol_cats=vol.categories foreach(vol_cat in vol_cats) { postings=postings + vol_cat.postings } Please Help me Thank you -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, Jun 11, 2012 at 12:04 PM, saroj s. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I want to find out all the postings of the categories that the > volunteer is interested in.Sounds like you want a "has_many :through" relationship. -Dave -- Dave Aronson, Cleared/Remote Ruby on Rails Freelancer (NoVa/DC/Remote); see www.DaveAronson.com, and blogs at www.Codosaur.us, www.Dare2XL.com, www.RecruitingRants.com -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Solution: http://stackoverflow.com/questions/10983337/active-record-querying-rails-3-2-1 -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.