我想知道是否有轨道方式来销毁has_many关联,给定一个条件。 买家Rails - 销毁'连接表'协会
class Buyer < ActiveRecord::Base
has_many :phones, as: :phoneable, dependent: :destroy, class_name: 'Telephone'
end
电话
class Telephone < ActiveRecord::Base
belongs_to :phoneable, polymorphic: true
end
我想加入与电话买家,并销毁所有电话where('buyers.tel = telephones.number')
。写这个查询的最好方法是什么?
如果表格目前不存在,我会建议创建一个migrat以创建连接表。然后写一个rake任务来填充它。 – onebree