Offeride :limit named_scope default_scope

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.

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. <

On Wed, Jul 22, 2009 at 12:02 AM, Dingding Ye [email protected]
wrote:

Hi,

TestD.all

Posted via 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs