Class: ActiveRecord::Associations::JoinDependency
- Inherits:
-
Object
- Object
- ActiveRecord::Associations::JoinDependency
- Defined in:
- lib/calculated_attributes/rails_3_patches.rb,
lib/calculated_attributes/rails_4_patches.rb,
lib/calculated_attributes/rails_5_patches.rb,
lib/calculated_attributes/rails_6_patches.rb,
lib/calculated_attributes/rails_5_2_patches.rb
Instance Attribute Summary collapse
-
#calculated_columns ⇒ Object
writeonly
Sets the attribute calculated_columns.
Instance Method Summary collapse
Instance Attribute Details
#calculated_columns=(value) ⇒ Object (writeonly)
Sets the attribute calculated_columns
51 52 53 |
# File 'lib/calculated_attributes/rails_3_patches.rb', line 51 def calculated_columns=(value) @calculated_columns = value end |
Instance Method Details
#instantiate(result_set, &block) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/calculated_attributes/rails_3_patches.rb', line 53 def instantiate(rows) primary_key = join_base.aliased_primary_key parents = {} records = rows.map do |model| primary_id = model[primary_key] parent = parents[primary_id] ||= join_base.instantiate(model) construct(parent, @associations, join_associations, model) @calculated_columns.each { |column| parent[column.right] = model[column.right] } parent end.uniq remove_duplicate_results!(active_record, records, @associations) records end |