I have this tipical has_many :through scenario: class Docs < ActiveRecord::Base has_many :doc_cats has_many :categories, :through => :doc_cats end class Categories < ActiveRecord::Base has_many :doc_cats has_many :docs, :through => :doc_cats end class Doc_cats < ActiveRecord::Base belongs_to :docs belongs_to :categories end Now I would like to get all docs which have (belong to) categories 2 and 4. How to specify find clouse? @docs = Docs.find(:all, .......... etc) by TheR -- 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-/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 did not tried on console, but is something like this: @docs = Doc.find(:all, :include => [:doc_cats], :conditions => ''doc_cats.category_id in [2,4]'') Damjan Rems wrote:> I have this tipical has_many :through scenario: > > class Docs < ActiveRecord::Base > has_many :doc_cats > has_many :categories, :through => :doc_cats > end > > class Categories < ActiveRecord::Base > has_many :doc_cats > has_many :docs, :through => :doc_cats > end > > class Doc_cats < ActiveRecord::Base > belongs_to :docs > belongs_to :categories > end > > Now I would like to get all docs which have (belong to) categories 2 and > 4. How to specify find clouse? > > @docs = Docs.find(:all, .......... etc) > > > by > TheR > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
flaubert wrote:> i did not tried on console, but is something like this: > > @docs = Doc.find(:all, :include => [:doc_cats], :conditions => > ''doc_cats.category_id in [2,4]'')Thank you very much. It works. Of course I had to update table mames. by TheR -- 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-/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 -~----------~----~----~----~------~----~------~--~---