So lets say I have a table that's setup with Single Table Inheritance:
class Employee < Sequel::Model
plugin :single_table_inheritance, :kind
class Staff < self; end
class Manager < self; end
end
and I create the new record and then subsequently want to update the employee role, like so:
employee = Employee::Manager.create
employee.update(kind: "staff")
The issue I'm having is that employee.class still returns Employee::Manager instead of Employee::Staff and doing a employee.reload results in a Sequel::NoExistingObject: Record not found.
Looking at the resulting sql its obvious that's its still trying to find the record using the old type:
SELECT * FROM "employees" WHERE (("employees"."kind" IN ('manager')) AND ("id" = 1)) LIMIT 1
The only way I've been able to get around this is to reload the record from the id:
employee = Employee[employee.id]
Am I missing something or this the only way to refresh the updated record?
Thanks in advance!
First of all according to your example, you are doing your update in wrong way. It should be like
because
Employeeis like a namespace in your example.And then you can load it class, by calling
sti_loadon class. there is some variations