method
insert_record
v4.0.2 -
Show latest stable
-
0 notes -
Class: ActiveRecord::Associations::HasAndBelongsToManyAssociation
insert_record(record, validate = true, raise = false)
public
Hide source
# File activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb, line 12 def insert_record(record, validate = true, raise = false) if record.new_record? if raise record.save!(:validate => validate) else return unless record.save(:validate => validate) end end if options[:insert_sql] owner.connection.insert(interpolate(options[:insert_sql], record)) else stmt = join_table.compile_insert( join_table[reflection.foreign_key] => owner.id, join_table[reflection.association_foreign_key] => record.id ) owner.class.connection.insert stmt end record end