many-to-many relationship and sorting

[prev] [thread] [next] [Date index for 2005/03/09]

From: Hartmaier Alexander
Subject: many-to-many relationship and sorting
Date: 11:26 on 09 Mar 2005
So something like that would do the trick?

my @films =3D map { $_->film } Role->search( actor =3D> $actor, {order_by=
 =3D> 'name'} );

-Alex


-----Urspr=FCngliche Nachricht-----
Von: William Ross [mailto:will@xxxxxxx.xxx]=20
Gesendet: Mittwoch, 9. M=E4rz 2005 12:14
An: Hartmaier Alexander
Cc: cdbi-talk@xxxxxx.xxxxx.xxx
Betreff: Re: many-to-many relationship and sorting

On 9 Mar 2005, at 10:29, Hartmaier Alexander wrote:

> How does the mapping method work internally?
> I thought it retrieves all id's of the foreign class (table) with a=20
> single sql statement...then only an ORDER BY sql clause would be=20
> needed...

The has_many(x =3D> [y =3D> z]) shortcut you're using doesn't change the=20=

SQL generated by has_many: it just adds an extra inflation step after=20
the foreign ids have been retrieved from the linking table. The=20
destination table in a m2m relationship is never touched, so there is=20
no chance to order the results by something in that table.

If you look at Class::DBI::Relationship::HasMany->_hm_run_search,=20
you'll see that it just calls search() on the linking class. So with=20
this:

	Actor->has_many(films =3D> [ Role =3D> 'film' ]);

these two statements are _exactly_ the same:

	my @films =3D $actor->films;
	my @films =3D map { $_->film } Role->search( actor =3D> $actor );

I thought Matt's HasManytoMany looked good: thoughtful and=20
well-constructed, and it will do what you need. the documentation is a=20=

bit sparse, though :)

best

will


*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*=
"*"*
Hinweis: Dieses E-mail kann vertrauliche und gesch=FCtzte Informationen e=
nthalten.
Sollten Sie nicht der beabsichtigte Empf=E4nger sein, verst=E4ndigen Sie =
bitte den Absender und l=F6schen Sie dieses E-mail dann sofort.

Notice: This e-mail contains information that is confidential and may be =
privileged.
If you are not the intended recipient, please notify the sender and then =
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*=
"*"*

(message missing)

many-to-many relationship and sorting
Hartmaier Alexander 15:48 on 08 Mar 2005

Re: many-to-many relationship and sorting
Perrin Harkins 16:08 on 08 Mar 2005

many-to-many relationship and sorting
Hartmaier Alexander 16:14 on 08 Mar 2005

Re: many-to-many relationship and sorting
Perrin Harkins 17:52 on 08 Mar 2005

Re: many-to-many relationship and sorting
Matt S Trout 20:25 on 08 Mar 2005

Re: many-to-many relationship and sorting
Jay Strauss 18:37 on 08 Mar 2005

many-to-many relationship and sorting
Hartmaier Alexander 09:31 on 09 Mar 2005

Re: many-to-many relationship and sorting
Tony Bowden 09:53 on 09 Mar 2005

Re: many-to-many relationship and sorting
Matt S Trout 15:29 on 12 Mar 2005

many-to-many relationship and sorting
Hartmaier Alexander 10:29 on 09 Mar 2005

Re: many-to-many relationship and sorting
Tony Bowden 10:55 on 09 Mar 2005

Re: many-to-many relationship and sorting
William Ross 11:14 on 09 Mar 2005

many-to-many relationship and sorting
Hartmaier Alexander 11:26 on 09 Mar 2005

Re: many-to-many relationship and sorting
William Ross 11:36 on 09 Mar 2005

many-to-many relationship and sorting
Hartmaier Alexander 12:24 on 09 Mar 2005

Re: many-to-many relationship and sorting
Tony Bowden 12:57 on 09 Mar 2005

Re: many-to-many relationship and sorting
Jay Strauss 14:15 on 09 Mar 2005

Re: many-to-many relationship and sorting
Tony Bowden 15:14 on 09 Mar 2005

Re: many-to-many relationship and sorting
Perrin Harkins 17:31 on 09 Mar 2005

Problem 'setting' data.
John Day 23:00 on 09 Mar 2005

Re: Problem 'setting' data.
Michael Peters 23:12 on 09 Mar 2005

Re: Problem 'setting' data.
Jason Galea 23:30 on 09 Mar 2005

Re: many-to-many relationship and sorting
Matt S Trout 15:31 on 12 Mar 2005

Generated at 08:54 on 14 Mar 2005 by mariachi v0.52