This project is archived and is in readonly mode.
Default scope with :conditions => "a string"
-
Bruno Michel
This patch also fixes the #2199 bug (with a test case to prove it).
-
Arnaud Berthomier
+1
Works for me, thanks!
-
Nick M
This same patch also fixes an "undefined method
merge'" error when trying to access a has_many relationship where the primary_key is specified and the associated model uses default_scope. If that doesn't make sense, I've attached another test case showing the problem that this fixes.Thanks!
-
Eloy Duran
- Assigned user set to Manfred Stienstra
-
Steven Soroka
I had:
default_scope :conditions => ['available != ?', 1]and this fixed the problem; however, I don't think default_scope should be assuming it can use the conditions, even if it is a hash, for default create options. What if my conditions said {:available => '!= 1'} or {:available => '> 1'} ? I believe those are valid, but still cannot be used as default create options.
Perhaps default_scope should be changed to take a :create parameter and use that or nothing.
-
Bruno Michel
I don"t think that {:available => '!= 1'} or {:available => '> 1'} are valid, but it can be a good idea to have a :create parameter when we want different conditions for creating objects and finding them. For example, the default status of an article can be 'draft' (not visible by default), but the default_scope uses {:status => 'public'} for listing only public articles.
-
Manfred Stienstra
- State changed from new to open
I'll include this in with "the big scopes rewrite".
-
qoobaa
It also fixes the bug with aggregate functions like count:
class Card < ActiveRecord::Base default_scope :conditions => "some string or array condition" end Card.count NoMethodError: undefined method `merge' for "some string or array condition":String -
qoobaa
It also fixes the bug with aggregate functions like count:
class Card < ActiveRecord::Base default_scope :conditions => "some string or array condition" end Card.count # NoMethodError: undefined method merge' for [some string or array condition](String)Sorry, Lighthouse understands only "ruby" in lowercase, can't edit previous post (that sucks).
-
Michael Koziarski
- Milestone changed from 2.x to 2.3.4
Manfred,
Seems like we should be able to get a fix for this into 2.3.4 in addition to master/3.0?
-
Manfred Stienstra
The scopes rewrite is based on 2.3, so in theory you could apply it to both. I wouldn't expect it to be fully finished really soon though.
-
Rizwan Reza
- Tag changed from active_record, bug, default_scope, patch to active_record, bug, bugmash, default_scope, patch
-
Paul Gideon Dann
- Tag changed from active_record, bug, bugmash, default_scope, patch to arel rails3, active_record, bug, bugmash, default_scope, patch, rails3rc
- Importance changed from to High
I'm seeing this issue in Rails 3.0.0.rc when I set a default_scope to an "order" clause. It seems like a pretty big deal. Can this patch be forward-ported to Rails3?
-
Santiago Pastorino
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
- State changed from open to stale
