diff options
author | Emilio Tagua <miloops@gmail.com> | 2011-02-18 15:29:33 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2011-02-18 15:29:33 -0300 |
commit | 0b702ba3de42ed2ae8855843127f898102802b77 (patch) | |
tree | fc7d9b2fd78c3558dd978f3b67e5e58792551668 /activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb | |
parent | 90a850aea4c2c04df22be0aaad1144468fcc8078 (diff) | |
parent | 1644663ba7f678d178deab2bf1629dc05626f85b (diff) | |
download | rails-0b702ba3de42ed2ae8855843127f898102802b77.tar.gz rails-0b702ba3de42ed2ae8855843127f898102802b77.tar.bz2 rails-0b702ba3de42ed2ae8855843127f898102802b77.zip |
Merge remote branch 'rails/master' into identity_map
Conflicts:
activerecord/lib/active_record/associations/association.rb
activerecord/lib/active_record/fixtures.rb
Diffstat (limited to 'activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb index b9c9919e7a..bcaea5ded4 100644 --- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb @@ -1,7 +1,7 @@ module ActiveRecord # = Active Record Has And Belongs To Many Association module Associations - class HasAndBelongsToManyAssociation < AssociationCollection #:nodoc: + class HasAndBelongsToManyAssociation < CollectionAssociation #:nodoc: attr_reader :join_table def initialize(owner, reflection) @@ -9,28 +9,26 @@ module ActiveRecord super end - protected + def insert_record(record, validate = true) + return if record.new_record? && !record.save(:validate => validate) - def insert_record(record, validate = true) - return if record.new_record? && !record.save(:validate => validate) + if @reflection.options[:insert_sql] + @owner.connection.insert(interpolate(@reflection.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 + ) - if @reflection.options[:insert_sql] - @owner.connection.insert(interpolate(@reflection.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.connection.insert stmt.to_sql - end - - record + @owner.connection.insert stmt.to_sql end - def association_scope - super.joins(construct_joins) - end + record + end + + def association_scope + super.joins(construct_joins) + end private |