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
Instance Method Summary
- #arel_columns(table)
- #cast(values, model)
- #expects_multiple_ids?(value) ⇒ 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.
- #value_of(record)
- #where_clauses(values)
- #where_hash(values)
Constructor Details
.new(columns) ⇒ Composite
Instance Attribute Details
#composite? ⇒ Boolean (readonly)
[ GitHub ]
# File 'activerecord/lib/active_record/key.rb', line 128
def composite? true end
Instance Method Details
#arel_columns(table)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 136
def arel_columns(table) @columns.map { |column| table[column] } end
#cast(values, model)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 140
def cast(values, model) @columns.zip(values).map! { |column, value| model.type_for_attribute(column).cast(value) } end
#expects_multiple_ids?(value) ⇒ Boolean
[ GitHub ]
# File 'activerecord/lib/active_record/key.rb', line 150
def expects_multiple_ids?(value) value.first.is_a?(Array) 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 156
def inferred_id @columns.include?("id") ? "id" : @name end
#value_of(record)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 144
def value_of(record) @columns.map { |column| record._read_attribute(column) } end
#where_clauses(values)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 160
def where_clauses(values) values.map { |set| where_hash(set) } end
#where_hash(values)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 132
def where_hash(values) @columns.zip(values).to_h end