aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-05-19 17:07:56 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-05-19 17:07:56 +0000
commit190e04645bf7ae873d922064783a71a88e0060fd (patch)
treedc2dcd1068dab32fc6a08e45e55673af13601043 /activerecord/lib
parentb3fcf2fa3c55584c6cb23d2195fbdc2647cc84cd (diff)
downloadrails-190e04645bf7ae873d922064783a71a88e0060fd.tar.gz
rails-190e04645bf7ae873d922064783a71a88e0060fd.tar.bz2
rails-190e04645bf7ae873d922064783a71a88e0060fd.zip
Fixed that :delete_sql in has_and_belongs_to_many associations couldn't access record properties #1299 [Rick Olson]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1313 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb2
-rw-r--r--activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb4
2 files changed, 4 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 4b1de85a90..d0dde54015 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -506,6 +506,8 @@ module ActiveRecord
# has_and_belongs_to_many :projects
# has_and_belongs_to_many :nations, :class_name => "Country"
# has_and_belongs_to_many :categories, :join_table => "prods_cats"
+ # has_and_belongs_to_many :active_projects, :join_table => 'developers_projects', :delete_sql =>
+ # 'DELETE FROM developers_projects WHERE active=1 AND developer_id = #{id} AND project_id = #{record.id}'
def has_and_belongs_to_many(association_id, options = {})
validate_options([ :class_name, :table_name, :foreign_key, :association_foreign_key, :conditions,
:join_table, :finder_sql, :delete_sql, :insert_sql, :order, :uniq ], options.keys)
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 15211c2223..f827cf3282 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
@@ -136,7 +136,7 @@ module ActiveRecord
def delete_records(records)
if sql = @options[:delete_sql]
- records.each { |record| @owner.connection.execute(sql) }
+ records.each { |record| @owner.connection.execute(interpolate_sql(sql, record)) }
else
ids = quoted_record_ids(records)
sql = "DELETE FROM #{@join_table} WHERE #{@association_class_primary_key_name} = #{@owner.quoted_id} AND #{@association_foreign_key} IN (#{ids})"
@@ -145,7 +145,7 @@ module ActiveRecord
end
def construct_sql
- interpolate_sql_options!(@options, :finder_sql, :delete_sql)
+ interpolate_sql_options!(@options, :finder_sql)
if @options[:finder_sql]
@finder_sql = @options[:finder_sql]