Module: Torque::PostgreSQL::Relation::Inheritance
- Included in:
- Torque::PostgreSQL::Relation
- Defined in:
- lib/torque/postgresql/relation/inheritance.rb,
sig/torque/postgresql/relation/inheritance.rbs
Defined Under Namespace
Modules: Expansion
Constant Summary collapse
- RECORD_CLASS_TOKEN =
:_regclass
Instance Method Summary collapse
-
#expand_records(*types, **options) ⇒ relation
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) ⇒ self
Like #expand_records, but modifies relation in place.
-
#expand_records_eager_load_value ⇒ Boolean?
:nodoc:.
-
#expand_records_eager_load_value=(value) ⇒ Boolean?
:nodoc:.
-
#expand_records_scoped_value ⇒ Hash[model, Array[model]]
:nodoc:.
-
#expand_records_scoped_value=(value) ⇒ Hash[model, Array[model]]
:nodoc:.
-
#expand_records_values ⇒ Array[model]
:nodoc:.
-
#expand_records_values=(value) ⇒ Array[model]
:nodoc:.
-
#itself_only ⇒ relation
Specify that the results should come only from the table that the entries were created on.
-
#itself_only! ⇒ self
Like #itself_only, but modifies relation in place.
-
#itself_only_value ⇒ Boolean?
:nodoc:.
-
#itself_only_value=(value) ⇒ Boolean?
:nodoc:.
- #quote_column_name ⇒ String
- #quote_table_name ⇒ String
-
#select(*fields) {|arg0| ... } ⇒ 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) ⇒ relation
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.expand_records
# Runs one additional query per inherited table
Activity.expand_records(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) ⇒ self
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 ⇒ Boolean?
: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) ⇒ Boolean?
: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 ⇒ Hash[model, Array[model]]
: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) ⇒ Hash[model, Array[model]]
: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 ⇒ Array[model]
: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) ⇒ Array[model]
: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 ⇒ relation
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! ⇒ self
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 ⇒ Boolean?
: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) ⇒ Boolean?
: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 |
#quote_column_name ⇒ String
16 |
# File 'sig/torque/postgresql/relation/inheritance.rbs', line 16
def quote_column_name: (column_ref name) -> String
|
#quote_table_name ⇒ String
15 |
# File 'sig/torque/postgresql/relation/inheritance.rbs', line 15
def quote_table_name: (table_ref name) -> String
|
#select(*fields) {|arg0| ... } ⇒ 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 |