0

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 makes that are related to @campaign.models?

The simplest solution is Make.where(id: @campaign.models.pluck(:make_id), but it's not efficient.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Alex Antonov
  • 14,134
  • 7
  • 65
  • 142

0 Answers0