[Dbix-class] trouble with using 'select' in a search clause

Toby Corkindale tjc at wintrmute.net
Wed May 17 12:51:34 CEST 2006


On Wed, May 17, 2006 at 01:47:36AM -0700, John Napiorkowski wrote:
> Hi,
> 
> I'm trying to create a query to perform something like
> this:
> 
> SELECT me.*, invitees.* 
>   FROM members_invitees me  
>   JOIN invitees invitees 
>   ON ( invitees.invitee_id = me.invitee_id ) 
> WHERE ( member_id = 1 );

[snip]

> So the table "members_invitees" is a many to many
> table between "members" and "invitees".
> 
> According to the documentation I can append columns to
> the select statement.  Using the example given I
> created a query (this is using Catalyst but should
> show my meaning):
> 
> my $rs = $c->model("db::members_invitees")->search(
> 		
>   {
>     member_id => $member->member_id
>   },
>   {
>     select  =>['me.*','invitees.*'],
>     join  => 'invitees',
>   }
> 
> );

I'm just wondering, is there a good reason that you need to try and force those
extra columns to be included?

Why not just access them via the relationship accessor after you've received
the results of the search?

ie. 
my $rs = $c->model('db::members_invitees')->search(
    { member_id => $member->member_id }
);
while (my $i = $rs->next) {
    print "This member is " . $i->invitees->foo;
}


Or perhaps, just do a search on Invitees directly, if that's what you're after?
my $rs = $c->model('db::invitees')->search({
        'member.id' => $member->id
    },
    {
        join => { 'members_invitees' => 'members' }
    }
);

-toby


-- 
Turning and turning in the widening gyre/The falcon cannot hear the falconer;
Things fall apart, the centre cannot hold/Mere anarchy is loosed upon the world
(gpg --keyserver www.co.uk.pgp.net --recv-key B1CCF88E)



More information about the Dbix-class mailing list