0

考虑:

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它自己的表一样。

谢谢!

4

1 回答 1

1

Bingo:

class Person < ActiveRecord::Base
  self.abstract_class = true
end
于 2009-10-14T01:36:11.770 回答