On 2/03/11 9:24 AM, Josiah wrote:
Aha, yeah, I was asking for how to do it in the database (somehow I
glossed over the fact that group_by was not a datamapper call and it
was not actually issuing a group by in sql).  Is there a way to do
group by without sorting by that field as well?  I'd like to be able
to sort by one column and group by another.
Please provide the concrete SQL query you are trying to achieve
(or the input with expected output)

My brain doesn't work with Foo and joinedtable ;)


Thanks for your help so far,
Josiah

On Mar 1, 2:16 pm, Xavier Shay<[email protected]>  wrote:
On Mar 2, 6:03 am, Josiah<[email protected]>  wrote:>  What is the api for 
grouping by and sorting by a joined table in 1.1?

eg:

Foo.all( ... ).group_by(&:'joinedtable.some_field')

I'm not convinced this a datamapper method ... #group_by is provided
by activesupport, and you're using it with a proc. This happens in
ruby land, not in the DB, meaning you can do this:
.group_by {|record| record.joined_table.some_field }



and

Foo.all(order: [ :'joined_table.some_field'.asc ])

Foo.all(
   order: Foo.joined_table.some_field.asc,
   links:  [relationships['joined_table'].inverse]
)

(There is small chance I didn't get this fix merged in for 1.1, in
that case here is a hack to you can use to work 
around:http://rhnh.net/2010/12/01/ordering-by-a-field-in-a-join-model-with-d...)

Cheers,
Xavier









Thanks,
Josiah


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