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


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

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

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

Like #cast_records, but modifies relation in place



56
57
58
59
60
61
# File 'lib/torque/postgresql/relation/inheritance.rb', line 56

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

#cast_records_valuesObject

:nodoc:



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

def cast_records_values
  @values.fetch(:cast_records, FROZEN_EMPTY_ARRAY)
end

#cast_records_values=(value) ⇒ Object

:nodoc:



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

def cast_records_values=(value)
  assert_modifiable!
  @values[: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


35
36
37
# File 'lib/torque/postgresql/relation/inheritance.rb', line 35

def itself_only
  spawn.itself_only!
end

#itself_only!Object

Like #itself_only, but modifies relation in place.



40
41
42
43
# File 'lib/torque/postgresql/relation/inheritance.rb', line 40

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

#itself_only_valueObject

:nodoc:



19
20
21
# File 'lib/torque/postgresql/relation/inheritance.rb', line 19

def itself_only_value
  @values.fetch(:itself_only, nil)
end

#itself_only_value=(value) ⇒ Object

:nodoc:



23
24
25
26
# File 'lib/torque/postgresql/relation/inheritance.rb', line 23

def itself_only_value=(value)
  assert_modifiable!
  @values[:itself_only] = value
end