Thanks a bunch. This worked the way I wanted it to. With that said...

This seems like something that should be more obvious. Like:

default_order [:field.desc]

Just like a property declaration. The only ORM I have much experience  
with (aside from a wee bit of ActiveRecord) is Django and this is the  
sort of feature that integrates comfortably with an admin panel.

I'm really new here and new to DataMapper, Ruby and Merb in general,  
so I want to make it clear I'm not being critical and I don't want my  
tone interpreted as anything even bordering on "know it all."

What I am saying is that, as someone brand new, this is one of the  
first things I looked for in combination with a web framework. (The  
other two things you guys were quick to answer!)

On Dec 9, 2008, at 3:23 PM, Adam French wrote:

>
> From inside your Model class do:
>
> default_scope(:default).update(:order => [:created_at.desc])
>
> You'd essentially be 'update'ing the default query object that all
> calls to all() and first() start off with before applying the user's
> parameters
>
> class Post
>  include DataMapper::Resource
>  #... other properties here
>  default_scope(:default).update(:order => [:created_at.desc])
> end
>
> ===
> Adam French
> Project Manager
> Wieck Media
>
>
>
> On Tue, Dec 9, 2008 at 3:50 PM, cult hero <[EMAIL PROTECTED]>  
> wrote:
>>
>> I know I can set the order of a collection when call .all()  
>> or .find()
>> or whatever, but is there a way to set a default sorting order?
>>
>> So, instead of it sorting by the key field by default, can I make it
>> so every time I get a collection back from a class that includes
>> DataMapper::Resource it sorts by another field.
>>
>> I found a "default_order" method, but that appears to apply to
>> repositories which doesn't help for what I'm trying to do.
>>>
>>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" 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/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to