Sha256: eb028509ee79af915fc588f73c24abdbb9aca6796bbdd86c319ac0342c685b19
Contents?: true
Size: 889 Bytes
Versions: 2
Compression:
Stored size: 889 Bytes
Contents
module HasUuid module ActiveRecord module Associations module CollectionAssociation extend ActiveSupport::Concern included do def uuids_reader if loaded? || options[:finder_sql] load_target.map do |record| record.send(reflection.association_primary_uuid) end else column = "#{reflection.quoted_table_name}.#{reflection.association_primary_uuid}" association_scope.pluck(column) end end def uuids_writer(uuids) uuid_column = reflection.primary_uuid_column uuids = Array(uuids).reject { |uuid| uuid.blank? } uuids.map! { |u| uuid_column.type_cast(u) } replace(klass.find(uuids).index_by { |r| r.uuid }.values_at(*uuids)) end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rails_has_uuid-0.3.0 | lib/has_uuid/active_record/associations/collection_association.rb |
rails_has_uuid-0.2.0 | lib/has_uuid/active_record/associations/collection_association.rb |