From 2464c96e14c22b52ba0a55898c0a3a7cd6bbfef9 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 23 Aug 2010 06:08:26 +0900 Subject: [PATCH] Compare not only by attribute_name but by attribute_name and table_name when compiling scope_for_create --- activerecord/lib/active_record/relation.rb | 2 +- activerecord/test/cases/method_scoping_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 03b0620..24c5753 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -318,7 +318,7 @@ module ActiveRecord def where_values_hash Hash[@where_values.find_all { |w| - w.respond_to?(:operator) && w.operator == :== + w.respond_to?(:operator) && (w.operator == :==) && (w.operand1.relation == self.arel_table) }.map { |where| [where.operand1.name, where.operand2.respond_to?(:value) ? diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb index 312628a..2fafe6e 100644 --- a/activerecord/test/cases/method_scoping_test.rb +++ b/activerecord/test/cases/method_scoping_test.rb @@ -226,6 +226,12 @@ class MethodScopingTest < ActiveRecord::TestCase assert Post.find(1).comments.include?(new_comment) end + def test_scoped_create_with_join_and_merge + (Comment.where(:body => "but Who's Buying?").joins(:post) & Post.where(:body => 'Peace Sells...')).with_scope do + assert_equal({:body => "but Who's Buying?"}, Comment.scoped.scope_for_create) + end + end + def test_immutable_scope options = { :conditions => "name = 'David'" } Developer.send(:with_scope, :find => options) do -- 1.7.2.1