Skip to content

Instantly share code, notes, and snippets.

@filiptepper
Created December 22, 2010 12:05
Show Gist options
  • Save filiptepper/751434 to your computer and use it in GitHub Desktop.
Save filiptepper/751434 to your computer and use it in GitHub Desktop.
class ModelBase < ActiveRecord::Base
end
class BaseA < ModelBase
has_many :things, :as => :model_a
end
class BaseB < ModelBase
has_many :things, :as => :model_b
end
class Thing < ActiveRecord::Base
belongs_to :model_a, :polymorphic => true
belongs_to :model_b, :polymorphic => true
end
t = Thing.create :model_a => BaseA.first, model_b => BaseB.first
=> #<Thins model_a_type: "ModelBase", :model_b_type, "ModelBase"
^^^^^^^^^
Expected BaseA
^^^^^^^^^
Expected BaseB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment