Sha256: 9d425b48016c78cd315068ba362e244615a0bc79cb99a47fc9abf856bd0de371
Contents?: true
Size: 948 Bytes
Versions: 22
Compression:
Stored size: 948 Bytes
Contents
class ActiveRecord::Associations::HasManyThroughAssociation def insert_record(record, validate = true, raise = false) ensure_not_nested if record.new_record? if raise record.save!(validate: validate) else return unless record.save(validate: validate) end end save_through_record(record) #update_counter(1) record end def delete_records(records, method) ensure_not_nested scope = through_association.scope.where(construct_join_attributes(*records)) case method when :destroy count = scope.destroy_all.length when :nullify count = scope.update_all(source_reflection.foreign_key => nil) else count = scope.delete_all end delete_through_records(records) if through_reflection.macro == :has_many && update_through_counter?(method) update_counter(-count, through_reflection) end #update_counter(-count) end end
Version data entries
22 entries across 22 versions & 2 rubygems