Josiah | 1 Mar 2011 20:03
Picon
Gravatar

Group by on joined table in 1.1.0.rc1

What is the api for grouping by and sorting by a joined table in 1.1?

eg:

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

and

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

Thanks,
Josiah

--

-- 
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To post to this group, send email to datamapper@...
To unsubscribe from this group, send email to datamapper+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.

Xavier Shay | 1 Mar 2011 23:16
Favicon
Gravatar

Re: Group by on joined table in 1.1.0.rc1


On Mar 2, 6:03 am, Josiah <bluep...@...> 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-datamapper)

Cheers,
Xavier

>
> Thanks,
(Continue reading)

Josiah | 1 Mar 2011 23:24
Picon
Gravatar

Re: Group by on joined table in 1.1.0.rc1

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.

Thanks for your help so far,
Josiah

On Mar 1, 2:16 pm, Xavier Shay <xav...@...> wrote:
> On Mar 2, 6:03 am, Josiah <bluep...@...> 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,
(Continue reading)

Xavier (DBIYF | 1 Mar 2011 23:26
Favicon
Gravatar

Re: Re: Group by on joined table in 1.1.0.rc1


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<xav...@...>  wrote:
>> On Mar 2, 6:03 am, Josiah<bluep...@...>  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 }
>>
>>
(Continue reading)

Josiah | 2 Mar 2011 00:30
Picon
Gravatar

Re: Group by on joined table in 1.1.0.rc1

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
(Continue reading)

Josiah | 2 Mar 2011 00:40
Picon
Gravatar

Re: Group by on joined table in 1.1.0.rc1

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 <bluep...@...> 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
(Continue reading)

Josiah | 2 Mar 2011 01:45
Picon
Gravatar

Re: Group by on joined table in 1.1.0.rc1

Turns out I was a little too trigger happy:

There are some cases I need the group by where a second order by won't
work.  Back to my original question: is this possible?

Josiah

On Mar 1, 6:40 pm, Josiah <bluep...@...> wrote:
> 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 <bluep...@...> 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
(Continue reading)

Dan Kubb (dkubb | 2 Mar 2011 07:05
Picon
Gravatar

DataMapper 1.1.0.rc2 Released

I just wanted to drop a quick note that DataMapper 1.1.0.rc2 is out
for testing.

I'll follow up with official release notes about what's changed since
1.0.2 later on, but it's mostly bug fixes, internal refactoring/
simplification and a few minor API changes.

We did a soft launch yesterday and only notified people in the
#datamapper IRC channel because we wanted to make sure there were no
build/dependency issues first. It turned out that dm-rails did have
one small problem with dependencies, which has been fixed, and now
we're announcing to the mailing list and twitter.

Please note that if you're using gem to install these pre-release gems
use the --pre flag otherwise rubygems will ignore them. With bundler
you just have to specify the version with the ".rc2" suffix and
everything will work as normal.

--

Dan
(dkubb)

--

-- 
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To post to this group, send email to datamapper@...
To unsubscribe from this group, send email to datamapper+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.

(Continue reading)

Hameed Gifford | 2 Mar 2011 00:55
Picon
Gravatar

Re: Re: Group by on joined table in 1.1.0.rc1

And so strikes the teddy bear at the help desk

- h85

On Tue, 2011-03-01 at 15:40 -0800, Josiah wrote:
> 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 <bluep...@...> 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:
(Continue reading)

Josiah | 2 Mar 2011 17:07
Picon
Gravatar

Re: Group by on joined table in 1.1.0.rc1

Yeah, sorry bout that. Turns out I misunderstood the purpose of GROUP
BY.

Thanks for putting up with me. ;)
Josiah

On Mar 1, 3:55 pm, Hameed Gifford <giff....@...> wrote:
> And so strikes the teddy bear at the help desk
>
> - h85
>
>
>
>
>
>
>
> On Tue, 2011-03-01 at 15:40 -0800, Josiah wrote:
> > 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 <bluep...@...> wrote:
> > > My tables look like this:http://pastie.org/1622672
> > > (This is a legacy database: I tried to distill the classes down to
(Continue reading)


Gmane