Skip to content

Instantly share code, notes, and snippets.

@josiasds
Last active August 29, 2015 14:05
Show Gist options
  • Save josiasds/897c20342813a7281f66 to your computer and use it in GitHub Desktop.
Save josiasds/897c20342813a7281f66 to your computer and use it in GitHub Desktop.
Polymorphic Timelines
class Campaign < ActiveRecord::Base
has_many :timelines, :through => :assignment
end
class Timeline < ActiveRecord::Base
self.abstract_class = true
end
class Assignment < ActiveRecord::Base
belongs_to :campaign
belongs_to :timeline, :polymorphic => true
end
class FbAuth < Timeline
has_many :campaigns, :through => :assignment, :as => :timeline
end
class TwAuth < Timeline
has_many :campaigns, :through => :assignment, :as => :timeline
end
class FbPage < Timeline
has_many :campaigns, :through => :assignment, :as => :timeline
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment