From 1d316ac1fd68962782762b02694a1bf9fd4ef44e Mon Sep 17 00:00:00 2001 From: Nat Budin Date: Mon, 12 May 2014 14:30:05 -0700 Subject: Make filter_binds filter out symbols that are equal to strings ActiveRecord::Relation::Merger's filter_binds method does not filter out bind variables when one of the attribute nodes has a string name, but the other has a symbol name, even when those names are actually equal. This can result in there being more bind variables than placeholders in the generated SQL. This is particularly an issue for PostgreSQL, where this is treated as an error. This patch changes the filter_binds method to make it convert both attribute names to strings before comparing. --- activerecord/test/models/comment.rb | 8 ++++++++ activerecord/test/models/post.rb | 9 +++++++++ 2 files changed, 17 insertions(+) (limited to 'activerecord/test/models') diff --git a/activerecord/test/models/comment.rb b/activerecord/test/models/comment.rb index f82df417ce..d44befbfd2 100644 --- a/activerecord/test/models/comment.rb +++ b/activerecord/test/models/comment.rb @@ -40,3 +40,11 @@ end class VerySpecialComment < Comment end + +class CommentThatAutomaticallyAltersPostBody < Comment + belongs_to :post, class_name: "PostThatLoadsCommentsInAnAfterSaveHook", foreign_key: :post_id + + after_save do |comment| + comment.post.update_attributes(body: "Automatically altered") + end +end \ No newline at end of file diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index b1e56c14d1..4ee67a4bb3 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -208,3 +208,12 @@ class SpecialPostWithDefaultScope < ActiveRecord::Base self.table_name = 'posts' default_scope { where(:id => [1, 5,6]) } end + +class PostThatLoadsCommentsInAnAfterSaveHook < ActiveRecord::Base + self.table_name = 'posts' + has_many :comments, class_name: "CommentThatAutomaticallyAltersPostBody", foreign_key: :post_id + + after_save do |post| + post.comments.load + end +end -- cgit v1.2.3