Sha256: 9c19d475eb1fdbc6932c70dbfcafae0288d47baac3c850029c1368ec98b49156
Contents?: true
Size: 732 Bytes
Versions: 6
Compression:
Stored size: 732 Bytes
Contents
module AbstractImporter class Collection < Struct.new(:name, :model, :table_name, :scope, :options) def association_attrs return @assocation_attrs if defined?(@assocation_attrs) # Instead of calling `tenant.people.build(__)`, we'll reflect on the # association to find its foreign key and its owner's id, so that we # can call `Person.new(__.merge(tenant_id: id))`. @assocation_attrs = {} assocation = scope.instance_variable_get(:@association) unless assocation.is_a?(ActiveRecord::Associations::HasManyThroughAssociation) @assocation_attrs.merge!(assocation.reflection.foreign_key.to_sym => assocation.owner.id) end @assocation_attrs.freeze end end end
Version data entries
6 entries across 6 versions & 1 rubygems