has_many :through and with_scope protected

If you were following the excellent has_many :through blog, you may find you can't use with_scope in the methods defined on your association. Instead, just send :with_scope along.

has_many :active_campaigns, :through => :campaign_distributions do
  def <<(active_campaign)
    CampaignDistribution.send(:with_scope, :create => {}) {
      self.concat active_campaign
    }
  end
end

Post a Comment

Your email is never shared. Required fields are marked *

*
*