我有三种模式:
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
我有一个@campaign
变量和一个特殊的@campaign.models
值。
如何找到与make
相关的所有@campaign.models
?
最简单的解决方案是Make.where(id: @campaign.models.pluck(:make_id)
,但效率不高。