This project is archived and is in readonly mode.
with_scope merges :find conditions incorrectly
Reported by karol | August 19th, 2009 @ 06:28 PM
for the following code, it seems that argument "action" of with_scope ( = :merge or :reverse_merge) doesn't change anything example shows creation of two elements ( case 1 &2 - it works correctly) and the find ( case 3 & 4 - it works incorrectly in case 4 ) Article is a very simple class, with only one attribute - "title" (not counting id, created_at , etc. )
c = nil ; Article.delete_all puts "Articles:" pp Article.find(:all) puts "1:" Article.send(:with_scope, {:create => {:title => 'outside'} } ) do Article.send(:with_scope, {:create => { :title => 'inside' }}) do c = Article.create pp c end end puts "2:" Article.send(:with_scope, {:create => {:title => 'outside'} } ) do Article.send(:with_scope, {:create => { :title => 'inside' }}, :reverse_merge) do c = Article.create pp c end end puts "3:" Article.send(:with_scope, {:find => { :conditions => {:title => 'outside'} }} ) do Article.send(:with_scope, {:find => {:conditions => { :title => 'inside' }}} , :merge) do pp Article.find(:all) end end puts "4:" Article.send(:with_scope, :find => { :conditions => {:title => 'outside'} } ) do Article.send(:with_scope, {:find => {:conditions => { :title => 'inside' }}} , :reverse_merge) do pp Article.find(:all) end end
-- OUTPUT: ---
kkurach@honolulu:~/mytest$ ./xx.rb Articles: [] 1: Article id: 7, title: "inside", created_at: "2009-08-19 16:55:32", updated_at: "2009-08-19 16:55:32" 2: Article id: 8, title: "outside", created_at: "2009-08-19 16:55:32", updated_at: "2009-08-19 16:55:32" 3: Article id: 8, title: "outside", created_at: "2009-08-19 16:55:32", updated_at: "2009-08-19 16:55:32" 4: Article id: 8, title: "outside", created_at: "2009-08-19 16:55:32", updated_at: "2009-08-19 16:55:32"---END OF OUTPUT ---
my comment: I shouldn't get "outside" 3 times... it seems that in both cases find uses normal :merge, instead of :reverse_merge in case 4)
Comments and changes to this ticket
-
Ben Mills October 6th, 2010 @ 05:31 AM
Appears to still be broken in Rails master.
Rails 3 (edge) Ruby 1.8.7 outputs:
1:
=> #<Article id: 13, title: "inside", created_at: "2010-10-06 02:23:17", updated_at: "2010-10-06 02:23:17">
=> #<Article id: 14, title: "inside", created_at: "2010-10-06 02:23:22", updated_at: "2010-10-06 02:23:22"
=> [#<Article id: 13, title: "inside", created_at: "2010-10-06 02:23:17", updated_at: "2010-10-06 02:23:17">, #<Article id: 14, title: "inside", created_at: "2010-10-06 02:23:22", updated_at: "2010-10-06 02:23:22">]
=> [#<Article id: 13, title: "inside", created_at: "2010-10-06 02:23:17", updated_at: "2010-10-06 02:23:17">, #<Article id: 14, title: "inside", created_at: "2010-10-06 02:23:22", updated_at: "2010-10-06 02:23:22">]
-
Santiago Pastorino February 2nd, 2011 @ 04:59 PM
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino February 2nd, 2011 @ 04:59 PM
- State changed from open to stale
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>