Module: Torque::PostgreSQL::Inheritance

Extended by:
ActiveSupport::Concern
Defined in:
lib/torque/postgresql/inheritance.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#cast_recordObject

Cast the given object to its correct class



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/torque/postgresql/inheritance.rb', line 9

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