Created
July 26, 2012 17:40
-
-
Save r00k/3183409 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This works, right now: | |
class EmailCaptureCampaign < ActiveRecord::Base | |
has_many :campaign_merchants, :as => :campaignable, :dependent => :destroy | |
has_many :merchants, :through => :campaign_merchants | |
end | |
class Merchant < ActiveRecord::Base | |
has_many :campaign_merchants, :dependent => :destroy | |
has_many :campaigns, :through => :campaign_merchants, :source => :campaignable, :source_type => 'EmailCaptureCampaign' | |
end | |
class CampaignMerchant < ActiveRecord::Base | |
belongs_to :campaignable, :polymorphic => true | |
belongs_to :merchant | |
end | |
# I want to add a new kind of campaign: | |
class UserAcquisitionCampaign < ActiveRecord::Base | |
has_many :campaign_merchants, :as => :campaignable, :dependent => :destroy | |
has_many :merchants, :through => :campaign_merchants | |
end | |
# but the :source_type => 'EmailCaptureCampaign' in Merchant above disallows this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to have merchant.campaigns return a collection of all campaigns, which will be of type UserAcquisitionCampaign or EmailCaptureCampaign.