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


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

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

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

Like #cast_records, but modifies relation in place



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/torque/postgresql/relation/inheritance.rb', line 46

def cast_records!(*types, **options)
  record_class = self.class._record_class_attribute

  with!(record_class)
  if options[:filter]
    table = record_class.to_s.camelize.underscore
    where!(table => { record_class => types.map(&:table_name) })
  end

  self.cast_records_value = (types.present? ? types : model.casted_dependents.values)
  self
end

#cast_records_valueObject

:nodoc:



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

def cast_records_value; get_value(:cast_records); end

#cast_records_value=(value) ⇒ Object

:nodoc:



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

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


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

def itself_only
  spawn.itself_only!
end

#itself_only!Object

Like #itself_only, but modifies relation in place.



30
31
32
33
# File 'lib/torque/postgresql/relation/inheritance.rb', line 30

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

#itself_only_valueObject

:nodoc:



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

def itself_only_value; get_value(:itself_only); end

#itself_only_value=(value) ⇒ Object

:nodoc:



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

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