Module: Torque::PostgreSQL::Relation::Inheritance

Included in:
Torque::PostgreSQL::Relation
Defined in:
lib/torque/postgresql/relation/inheritance.rb

Instance Method Summary collapse

Instance Method Details

#cast_records(*types, **options) ⇒ Object

Enables the casting of all returned records. The result will include all the information needed to instantiate the inherited models

Activity.cast_records
# The result list will have many different classes, for all
# inherited models of activities


43
44
45
# File 'lib/torque/postgresql/relation/inheritance.rb', line 43

def cast_records(*types, **options)
  spawn.cast_records!(*types, **options)
end

#cast_records!(*types, **options) ⇒ Object

Like #cast_records, but modifies relation in place



48
49
50
51
52
53
# File 'lib/torque/postgresql/relation/inheritance.rb', line 48

def cast_records!(*types, **options)
  where!(regclass.cast(:varchar).in(types.map(&:table_name))) if options[:filter]
  self.select_extra_values += [regclass.as(_record_class_attribute.to_s)]
  self.cast_records_value = (types.present? ? types : model.casted_dependents.values)
  self
end

#cast_records_valueObject

:nodoc:



11
# File 'lib/torque/postgresql/relation/inheritance.rb', line 11

def cast_records_value; get_value(:cast_records); end

#cast_records_value=(value) ⇒ Object

:nodoc:



13
# File 'lib/torque/postgresql/relation/inheritance.rb', line 13

def cast_records_value=(value); set_value(:cast_records, value); end

#itself_onlyObject

Specify that the results should come only from the table that the entries were created on. For example:

Activity.itself_only
# Does not return entries for inherited tables


27
28
29
# File 'lib/torque/postgresql/relation/inheritance.rb', line 27

def itself_only
  spawn.itself_only!
end

#itself_only!Object

Like #itself_only, but modifies relation in place.



32
33
34
35
# File 'lib/torque/postgresql/relation/inheritance.rb', line 32

def itself_only!(*)
  self.itself_only_value = true
  self
end

#itself_only_valueObject

:nodoc:



16
# File 'lib/torque/postgresql/relation/inheritance.rb', line 16

def itself_only_value; get_value(:itself_only); end

#itself_only_value=(value) ⇒ Object

:nodoc:



18
# File 'lib/torque/postgresql/relation/inheritance.rb', line 18

def itself_only_value=(value); set_value(:itself_only, value); end