A polymorphic object that belongs to a quasi-STI object: object_type is incorrect
-
21-09-2019 - |
Question
Consider:
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'
Edit: I got confused for a while there. This is not really STI, it's just inheritance, as Employee
has its own table.
Thanks!
Solution
class Person < ActiveRecord::Base
self.abstract_class = true
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow