كائن متعدد الأشكال ينتمي إلى كائن شبه مستقر: Object_type غير صحيح

StackOverflow https://stackoverflow.com/questions/1563462

سؤال

يعتبر:

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'

تعديل: لقد شعرت بالارتباك لفترة من الوقت هناك. هذا ليس بالأمراض المنقولة جنسيا حقًا ، إنه مجرد ميراث ، مثل Employee له طاولته الخاصة.

شكرًا!

هل كانت مفيدة؟

المحلول

البنغو:

class Person < ActiveRecord::Base
  self.abstract_class = true
end
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top