This is from a ticket I opened at Lighthouse. Would like to get more
of a discussion going here.

"I have an app in which I need more complex order by clauses,
something like "select id from foo order by (field1 * field2)"

It looks like this isn't currently possible. Its not something that
should be done at the app level either imo, so I was hoping we could
add support for this in DM. I understand there's a certain need for
the fields to be standard so we can sort on the collection in ruby...I
was thinking maybe this could be done by transforming a order by
string into a lambda?

Anyway, would love to hear some thoughts on this. I talked with
namelessjson about it and he agreed it didn't seem possible currently,
but should be."

One other suggestion on the ticket was 'A related suggestion: ordering
by fields in the join table of a "has n :through => Resource" many-to-
many relationship.'

And Dan's response:

"I actually think this is a good idea, but we need to be really
careful about the API that we design this around.

IMHO, of all the Ruby ORM API's the most elegant is the one that
Ambition provides. I think if it weren't for the ParseTree dependency
(which locks it to MRI mostly) it would be something that more ORMs
would strive to emulate.

At the same time I've attempted to make Collection work as similarly
to Ambition in many ways as possible. One way that I haven't gotten to
quite yet is to emulate Ambition's sort_by syntax:

http://ambition.rubyforge.org/ad...

Here's an example of what it would look like for DM:

User.all.sort_by { |u| -u.age }

When the Collection is loaded, we could just have the sort_by block
yield to the object and sorted normally as an Enumerable. (no need to
pay the cost of the DB access when it's already all loaded) When the
Collection isn't loaded, we could have it yield to a sort of OrderBy
object. That object could support a "*" operator, among others, so
that conditions like the above could be described in Ruby code. It
should be possible to make it so ParseTree isn't a requirement for
this (I think after all is said and done, the only thing that'd
require ParseTree is the conditions, due to OR/AND and nesting).

The only thing this leaves out is the ability to specify a default
order for associations. We could make it so :order accepts a lambda,
or we could make a :sort_by parameter for the lambda, and have it use
the same API as the Collection#sort_by provides."

So, any thoughts? At worst being able to do something like Sequel does
with a LiteralString that is sent directly to the DB as you specify
would be nice. IMO, there are just times when you need to get in there
manually, but shouldn't have to write the entire query in SQL.

jack dempsey
--~--~---------~--~----~------------~-------~--~----~
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