Skip to content

Instantly share code, notes, and snippets.

@r00k
Created July 26, 2012 17:40
Show Gist options
  • Save r00k/3183409 to your computer and use it in GitHub Desktop.
Save r00k/3183409 to your computer and use it in GitHub Desktop.
# 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
@r00k
Copy link
Author

r00k commented Jul 26, 2012

I want to have merchant.campaigns return a collection of all campaigns, which will be of type UserAcquisitionCampaign or EmailCaptureCampaign.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment