Sha256: 99f326596f3c54e23805447e9c5d6ce46102120134244621b83338af248230da
Contents?: true
Size: 617 Bytes
Versions: 22
Compression:
Stored size: 617 Bytes
Contents
module RailsCoreExtensions class TransferRecords def initialize(parent, klass, options = {}) @parent = parent @klass = klass @options = options end def transfer_from(objects) record_ids = objects.flat_map { |o| o.send(@klass.name.underscore + '_ids') } unless record_ids.empty? @options[:foreign_key] ||= @parent.class.name.underscore + '_id' update_options = @options.except(:foreign_key) update_options[@options[:foreign_key]] = @parent.id @klass.where(id: record_ids).update_all(update_options) end end end end
Version data entries
22 entries across 22 versions & 1 rubygems