Class: ActiveRecord::Key::Composite
Do not use. This class is for internal use only.
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Key
|
|
|
Instance Chain:
self,
Key
|
|
| Inherits: |
Key
|
| Defined in: | activerecord/lib/active_record/key.rb |
Class Method Summary
- .new(columns) ⇒ Composite constructor
Instance Attribute Summary
- #composite? ⇒ Boolean readonly
-
#inferred_key
readonly
The Key form of #inferred_id.
Instance Method Summary
- #_value_of(record, normalizers = nil)
- #arel_columns(table)
- #cast(values, model)
- #expects_multiple_ids?(value) ⇒ Boolean
- #include?(column) ⇒ Boolean
-
#inferred_id
When a composite key has the conventional [tenant_key, "id"] shape, associations join on "id" alone; otherwise the whole key is used.
- #map_value
- #resolve_aliases(owner)
- #subset?(other) ⇒ Boolean
- #value_of(record, normalizers = nil)
- #where_clauses(values)
- #where_hash(values)
- #zip(other)
Constructor Details
.new(columns) ⇒ Composite
Instance Attribute Details
#composite? ⇒ Boolean (readonly)
[ GitHub ]
# File 'activerecord/lib/active_record/key.rb', line 252
def composite? true end
#inferred_key (readonly)
The Key form of #inferred_id.
# File 'activerecord/lib/active_record/key.rb', line 314
attr_reader :inferred_key
Instance Method Details
#_value_of(record, normalizers = nil)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 288
def _value_of(record, normalizers = nil) if normalizers Array.new(@columns.length) do |index| value = record._read_attribute(@columns[index]) normalizer = normalizers[index] normalizer ? normalizer.call(value) : value end else @columns.map { |column| record._read_attribute(column) } end end
#arel_columns(table)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 260
def arel_columns(table) @columns.map { |column| table[column] } end
#cast(values, model)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 264
def cast(values, model) casted = [] @columns.zip(values) do |column, value| casted << model.type_for_attribute(column).cast(value) end casted end
#expects_multiple_ids?(value) ⇒ Boolean
#include?(column) ⇒ Boolean
# File 'activerecord/lib/active_record/key.rb', line 320
def include?(column) @columns.include?(column) end
#inferred_id
When a composite key has the conventional [tenant_key, "id"] shape, associations join on "id" alone; otherwise the whole key is used.
# File 'activerecord/lib/active_record/key.rb', line 309
def inferred_id @inferred_key.name end
#map_value
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 272
def map_value(&) @columns.map(&) end
#resolve_aliases(owner)
[ GitHub ]
#subset?(other) ⇒ Boolean
#value_of(record, normalizers = nil)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 276
def value_of(record, normalizers = nil) if normalizers Array.new(@columns.length) do |index| value = record.read_attr(@columns[index]) normalizer = normalizers[index] normalizer ? normalizer.call(value) : value end else @columns.map { |column| record.read_attr(column) } end end
#where_clauses(values)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 316
def where_clauses(values) values.map { |set| where_hash(set) } end
#where_hash(values)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 256
def where_hash(values) @columns.zip(values).to_h end
#zip(other)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 248
def zip(other, &) @columns.zip(other.to_a, &) end