# Offeride :limit named\_scope default\_scope

**URL:** <https://www.ruby-forum.com/t/offeride-limit-named-scope-default-scope/171931>\
**Category:** Rails\
**Created:** [July 11, 2009, 5:55pm UTC](https://www.ruby-forum.com/t/offeride-limit-named-scope-default-scope/171931 "2009-07-11T17:55:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![benol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bb73d2/32.png) [@benol](https://www.ruby-forum.com/u/benol)\
**Post date:** [July 11, 2009, 5:55pm UTC](https://www.ruby-forum.com/t/offeride-limit-named-scope-default-scope/171931/1 "2009-07-11T17:55:11Z")

</div>

Hi,

Rails 2.3.2

class TestD \< ActiveRecord::Base  
default\_scope :limit =\> 12  
named\_scope :limit, lambda { |num| { :limit =\> num} }  
end

ruby script/console

> > TestD.all  
> > TestD Load (0.7ms) SELECT \* FROM “test\_ds” LIMIT 12  
> > =\> []
> 
> > TestD.limit(14)  
> > TestD Load (0.3ms) SELECT \* FROM “test\_ds” LIMIT 12  
> > =\> []

Any ideas why the default limit does not get overwritten?

M.

---

<div class="post-metadata">

**Author:** ![benol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bb73d2/32.png) [@benol](https://www.ruby-forum.com/u/benol)\
**Post date:** [July 22, 2009, 9:03am UTC](https://www.ruby-forum.com/t/offeride-limit-named-scope-default-scope/171931/2 "2009-07-22T09:03:55Z")

</div>

Seems it’s a bug of 2.3.2 and fixed in 2.3.3.  
Best regards.

sishen

On Sat, Jul 11, 2009 at 11:55 PM, Michal B. \<

---

<div class="post-metadata">

**Author:** ![benol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bb73d2/32.png) [@benol](https://www.ruby-forum.com/u/benol)\
**Post date:** [July 25, 2009, 5:13am UTC](https://www.ruby-forum.com/t/offeride-limit-named-scope-default-scope/171931/3 "2009-07-25T05:13:24Z")

</div>

On Wed, Jul 22, 2009 at 12:02 AM, Dingding Ye [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > Hi,
> > 
> > > > TestD.all  
> > > > –  
> > > > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

This works for me in Rails 2.3.3. For example, given the following  
named  
scopes:

default\_scope :limit =\> 12  
named\_scope :recent, lambda { |limit| { :order =\> “posted\_at DESC”,  
:limit  
=\> limit } }  
named\_scope :limit, lambda { |limit| { :order =\> “posted\_at DESC”,  
:limit  
=\> limit } }

> Episode.all

=\> SELECT \* FROM `episodes` LIMIT 12  
SHOW FIELDS FROM `episodes`

> Episode.recent(10)

=\> SELECT \* FROM `episodes` ORDER BY posted\_at DESC LIMIT 10

> Episode.limit(10)

=\> SELECT \* FROM `episodes` ORDER BY posted\_at DESC LIMIT 10

-Conrad
