I have three models:
class Campaign < ActiveRecord::Base
has_and_belongs_to_many :models
has_and_belongs_to_many :makes
class Make < AR::Base
has_and_belongs_to_many :campaigns
has_many :models
class Model
has_and_belongs_to_many :campaigns
belongs_to :make
I have a @campaign
variable and a special @campaign.models
value.
How can I find all make
s that are related to @campaign.models
?
The simplest solution is Make.where(id: @campaign.models.pluck(:make_id)
, but it's not efficient.