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


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

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

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

Like #cast_records, but modifies relation in place



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

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:



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

def cast_records_value; get_value(:cast_records); end

#cast_records_value=(value) ⇒ Object

:nodoc:



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

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


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

def itself_only
  spawn.itself_only!
end

#itself_only!Object

Like #itself_only, but modifies relation in place.



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

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

#itself_only_valueObject

:nodoc:



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

def itself_only_value; get_value(:itself_only); end

#itself_only_value=(value) ⇒ Object

:nodoc:



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

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