This project is archived and is in readonly mode.
default_scope patch
Reported by Paweł Kondzior | November 15th, 2008 @ 09:42 PM | in 2.x
Default model scoping patch. With this AR will be able to set default scoping for models. For example it will be easier to get default order.
Comments and changes to this ticket
-
Paweł Kondzior November 15th, 2008 @ 09:44 PM
It's based on this http://dev.rubyonrails.org/ticke...
-
Paweł Kondzior November 16th, 2008 @ 12:21 PM
- Tag set to activerecord, patch, scope
I've added more tests for scopes
-
Paweł Kondzior November 16th, 2008 @ 02:51 PM
default_scope with named_scope syntaxt.
class Client < ActiveRecord::Base default_scope :order => 'name DESC' end
-
Paweł Kondzior November 16th, 2008 @ 02:52 PM
- no changes were found...
-
Repository November 16th, 2008 @ 03:01 PM
- State changed from new to committed
(from [ff594b2bc94ff2a942fe6ca05672387722dee686]) Added default_scope to Base [#1381 state:committed] (Paweł Kondzior) http://github.com/rails/rails/co...
-
DHH November 16th, 2008 @ 03:37 PM
- State changed from committed to open
This actually won't work with threads because:
def scoped_methods #:nodoc: Thread.current[:"#{self}_scoped_methods"] ||= [] end
So we need to promote default_scope to a class var and change the ||= [] to ||= default_scope.dup initialize default_scope to [].
-
Repository November 16th, 2008 @ 03:37 PM
- State changed from open to committed
(from [ca23287b448c2e007a5c93e43e762a10e0007b7a]) Revert "Added default_scope to Base [#1381 state:committed] (Paweł Kondzior)" -- won't gel with threads.
This reverts commit ff594b2bc94ff2a942fe6ca05672387722dee686. http://github.com/rails/rails/co...
-
Paweł Kondzior November 16th, 2008 @ 05:05 PM
cattr_accessor wont work, it will fail all because it will define default_scope for ActiveRecord::Base not for Model that inherts from it. So class var isn't solution here :(
-
Repository November 16th, 2008 @ 06:08 PM
(from [2530d0eea8eaecd2c61f99225f050ff47973e9a0]) Added default_scope to Base [#1381 state:committed] (Paweł Kondzior) http://github.com/rails/rails/co...
-
Tom Stuart November 17th, 2008 @ 08:19 PM
This doesn't work right in combination with other named scopes because
:create
is initialised tonil
if:conditions
isn't specified, causing a failure whenwith_scope
tries to callmerge
on it. The attached patch changes the behaviour to initialise:create
to{}
, which fixes the problem. Test included. -
Daniel Luz December 1st, 2008 @ 05:00 AM
The documentation is slightly out of date. This is a quick fix.
-
Michał Szajbe January 22nd, 2009 @ 01:38 PM
When default_scope's :conditions is something like { :field => ['val1', 'val2'] } then new record's field is initialized to "['val1', 'val2']" which is not desired behaviour I think. I am not sure how it should be initialized then, though.
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>
People watching this ticket
Attachments
Tags
Referenced by
- 1381 default_scope patch (from [ff594b2bc94ff2a942fe6ca05672387722dee686]) Added d...
- 1381 default_scope patch (from [ca23287b448c2e007a5c93e43e762a10e0007b7a]) Revert ...
- 1381 default_scope patch (from [2530d0eea8eaecd2c61f99225f050ff47973e9a0]) Added d...