11175
(-- --)
1
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
flaubert
(flaubert)
2
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:
11175
(-- --)
3
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