考虑:
class Person < ActiveRecord::Base
class << self
def setup
has_one :address, :as => :addressable
end
end
end
class Employee < Person
setup
end
class Address < ActiveRecord::Base
belongs_to :addressable, :polymorphic => true
end
# Shouldn't this be 'Employee'? Is it possible to override?
Employee.create.address.create.addressable_type == 'Person'
编辑:我在那里困惑了一段时间。这不是真正的 STI,它只是继承,就像Employee
它自己的表一样。
谢谢!