I just created a super simple prototype app to test this out:

I created a Post model:

class Post < ActiveRecord::Base
  named_scope :recent_by_id, lambda { |id| {
                :conditions => ['id > ?', id], :order => 'id ASC' } }
end

$ ./script/console
Loading development environment (Rails 2.1.1)
>> posts = Post.recent_by_id(1)

Development Log:
SELECT * FROM "posts" WHERE (id > 1) ORDER BY id ASC

Are you sure you are not including the :order somewhere else? This seems 
to work as expected.

Matt Constantine wrote:
> I have this simple named_scope that returns all Events after a given
> id:
> 
>  named_scope :recent_by_id, lambda {|id| {
>     :conditions => ['id > ?', id], :order => 'id ASC'
> }}
> 
> The problem is that named_scope returns a query with an order by
> clause containing created_at first:
> ORDER BY created_at DESC, id ASC
> 
> How do I get named_scope to ignore the created_at and simply give me a
> query sorted by id?
> 
> best,
> 
> - Matt
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to