Module: Torque::PostgreSQL::Relation::Inheritance
- Included in:
- Torque::PostgreSQL::Relation
- Defined in:
- lib/torque/postgresql/relation/inheritance.rb
Defined Under Namespace
Modules: Expansion
Constant Summary collapse
- RECORD_CLASS_TOKEN =
:_regclass
Instance Method Summary collapse
-
#expand_records(*types, **options) ⇒ Object
Load the columns that only exist on the inherited tables, so that records come out complete and writable.
-
#expand_records!(*types, eager_load: false, filter: false) ⇒ Object
Like #expand_records, but modifies relation in place.
-
#expand_records_eager_load_value ⇒ Object
:nodoc:.
-
#expand_records_eager_load_value=(value) ⇒ Object
:nodoc:.
-
#expand_records_scoped_value ⇒ Object
:nodoc:.
-
#expand_records_scoped_value=(value) ⇒ Object
:nodoc:.
-
#expand_records_values ⇒ Object
:nodoc:.
-
#expand_records_values=(value) ⇒ Object
:nodoc:.
-
#itself_only ⇒ Object
Specify that the results should come only from the table that the entries were created on.
-
#itself_only! ⇒ Object
Like #itself_only, but modifies relation in place.
-
#itself_only_value ⇒ Object
:nodoc:.
-
#itself_only_value=(value) ⇒ Object
:nodoc:.
-
#select(*fields) ⇒ Object
Accept the record class marker as a column, which is the only way an explicit selection can still produce casted records.
Instance Method Details
#expand_records(*types, **options) ⇒ Object
Load the columns that only exist on the inherited tables, so that records come out complete and writable. Defaults to every dependent that adds columns
Activity.
# Runs one additional query per inherited table
Activity.(ActivityBook, eager_load: true)
# Runs a single query using outer joins
78 79 80 |
# File 'lib/torque/postgresql/relation/inheritance.rb', line 78 def (*types, **) spawn.(*types, **) end |
#expand_records!(*types, eager_load: false, filter: false) ⇒ Object
Like #expand_records, but modifies relation in place
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/torque/postgresql/relation/inheritance.rb', line 83 def (*types, eager_load: false, filter: false) raise_itself_only_conflict! if itself_only_value === true types = types.presence || model..values where!(regclass.pg_cast(:varchar).in(types.map(&:table_name))) if filter self. = types self. = eager_load self end |
#expand_records_eager_load_value ⇒ Object
:nodoc:
19 20 21 |
# File 'lib/torque/postgresql/relation/inheritance.rb', line 19 def @values.fetch(:expand_records_eager_load, nil) end |
#expand_records_eager_load_value=(value) ⇒ Object
:nodoc:
23 24 25 26 |
# File 'lib/torque/postgresql/relation/inheritance.rb', line 23 def (value) assert_modifiable! @values[:expand_records_eager_load] = value end |
#expand_records_scoped_value ⇒ Object
:nodoc:
29 30 31 |
# File 'lib/torque/postgresql/relation/inheritance.rb', line 29 def @values.fetch(:expand_records_scoped, nil) || {} end |
#expand_records_scoped_value=(value) ⇒ Object
:nodoc:
33 34 35 36 |
# File 'lib/torque/postgresql/relation/inheritance.rb', line 33 def (value) assert_modifiable! @values[:expand_records_scoped] = value end |
#expand_records_values ⇒ Object
:nodoc:
9 10 11 |
# File 'lib/torque/postgresql/relation/inheritance.rb', line 9 def @values.fetch(:expand_records, FROZEN_EMPTY_ARRAY) end |
#expand_records_values=(value) ⇒ Object
:nodoc:
13 14 15 16 |
# File 'lib/torque/postgresql/relation/inheritance.rb', line 13 def (value) assert_modifiable! @values[:expand_records] = value end |
#itself_only ⇒ Object
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
57 58 59 |
# File 'lib/torque/postgresql/relation/inheritance.rb', line 57 def itself_only spawn.itself_only! end |
#itself_only! ⇒ Object
Like #itself_only, but modifies relation in place.
62 63 64 65 66 67 |
# File 'lib/torque/postgresql/relation/inheritance.rb', line 62 def itself_only!(*) raise_itself_only_conflict! if .present? self.itself_only_value = true self end |
#itself_only_value ⇒ Object
:nodoc:
39 40 41 |
# File 'lib/torque/postgresql/relation/inheritance.rb', line 39 def itself_only_value @values.fetch(:itself_only, nil) end |
#itself_only_value=(value) ⇒ Object
:nodoc:
43 44 45 46 |
# File 'lib/torque/postgresql/relation/inheritance.rb', line 43 def itself_only_value=(value) assert_modifiable! @values[:itself_only] = value end |
#select(*fields) ⇒ Object
Accept the record class marker as a column, which is the only way an explicit selection can still produce casted records
Activity.select(:_regclass, :id, :title)
98 99 100 101 102 103 |
# File 'lib/torque/postgresql/relation/inheritance.rb', line 98 def select(*fields) return super if fields.empty? return super(*fields, build_record_class_marker) if fields.delete(RECORD_CLASS_TOKEN) super end |