I have this model:
class Offer < ActiveRecord::Base
...
has_and_belongs_to_many :tags
...
end
and this:
class Tag < ActiveRecord::Base
...
has_and_belongs_to_many :offers
validates :name, presence: true
end
I want to find all offers that have relations with tag with a name on array
For example:
Offers1 -> Tag1, Tag2
Offers2 -> Tag2, Tag3
Offers3 -> Tag2, Tag3, Tag4
Tag1.name="test1"
Tag2.name="test2"
Tag3.name="test3"
Tag4.name="test4"
If i have this array ["test2","test3"]
i want to find Offers2
and Offers3
.
If i have this array ["test2","test3","test4"]
i want to find Offers3
.
I hope I have explained well, thanks for the help.