module Torque::PostgreSQL::Inheritance

Public Instance Methods

cast_record() click to toggle source

Cast the given object to its correct class

# File lib/torque/postgresql/inheritance.rb, line 11
def cast_record
  record_class_value = send(self.class._record_class_attribute)

  return self unless self.class.table_name != record_class_value
  klass = self.class.casted_dependents[record_class_value]
  self.class.raise_unable_to_cast(record_class_value) if klass.nil?

  # The record need to be re-queried to have its attributes loaded
  # :TODO: Improve this by only loading the necessary extra columns
  klass.find(self.id)
end