Aaaand I realize now that I don't want GROUP BY at all. I just want 2
ORDER BY columns.

Using the mock data I provided, swapping the order of the ORDER BY
columns will give the result I want.

Thanks for making me think through my problem completely.
Josiah

On Mar 1, 3:30 pm, Josiah <[email protected]> wrote:
> My tables look like this:http://pastie.org/1622672
> (This is a legacy database: I tried to distill the classes down to
> only what was important)
>
> I want to pull in TrackingGroupMember#name for each Bug and be able to
> sort and group on it.
>
> I also want to be able to sort by Bug#date_updated, for instance, and
> group on TrackingGroupMember#name in the same query.
>
> I basically want to treat TrackingGroupMember#name as if it were a
> column in Bug, as there will only ever be a 1 to 1 mapping (in this
> particular where clause) of TrackingGroupMember to Bug
>
> I want to group and sort like this:
>
> a|1
> c|2
> a|2
> a|3
> b|2
> b|1
> c|5
>
> If I group on the first column, and sort on the second column I want
> to see:
>
> a|1
> a|2
> a|3
> b|1
> b|2
> c|2
> c|5
>
> If I group on the second column and sort by the first, I want to see:
>
> a|1
> b|1
> a|2
> b|2
> c|2
> a|3
> c|5
>
> Does that sound possible?
>
> Thanks for your help.
> Josiah
>
> On Mar 1, 2:26 pm, "Xavier (DBIYF)" <[email protected]> wrote:
>
>
>
>
>
>
>
> > 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