Tiago,

> I'm trying to do something like this:
>
> class Account
>     include DataMapper::Resource
>
>     has n, :posts
> end
>
> class Post
>     include DataMapper::Resource
>
>     belongs_to :account
> end
>
> Post.all(:order => ["account.name"])

Currently you can't order results by another association, except
perhaps using sort_by, which does result in an extra query to load all
the Account objects for the posts, eg:

  Post.all.sort_by { |post| post.account.name }  # will execute 2
queries

Keep in mind that the resulting object will be an Array, so you won't
be able to use DM::Collection methods on it.

The reason for this limitation is that while it would be relatively
simple to do it with SQL in an RDBMS, it's difficult to apply this
concept to all adapters without some significant refactoring. I'm
working on a new query engine for DM 2.0 called Veritas that should
address this issue (and other issues) though:

  http://github.com/dkubb/veritas

--

Dan
(dkubb)

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