[Dbix-class] Fwd: [Catalyst] Selecting from more tables(DBIC-bug?)
Octavian Rasnita
octavian at fcc.ro
Wed Jan 20 15:28:32 GMT 2010
From: "Carl Johnstone" <dbixclass at fadetoblack.me.uk>
> Octavian Rasnita wrote:
>> my $uuu = $schema->resultset('User')->search({},{
>> prefetch => {blogs => 'blog_comments'},
>> select => ['me.id'],
>> as => ['user_id'],
>> });
>>
>> print $uuu->first->username;
>>
>> I know, but I would like to prefetch only just a few columns from the
>> joined tables, not all of them.
>>
>> Even if I would add to that arrayref some columns from the joined
>> table,
>> DBIC will get all the columns from those tables.
>
> If you called $uuu->first->blogs->title with the prefetch, it would
> perform
> another query and pull back all the columns in the related row.
>
> With prefetch you're giving DBIC a hint that you'll be performing those
> inflations, so it builds a single query (using a join) that allows it to
> pre-inflate. So currently the behaviour of DBIC with and without the
> prefetch are the same.
So is it not possible to create the following query with DBIC?
SELECT me.id, blogs.id, blog_comments.id
FROM user me LEFT JOIN blog blogs ON blogs.user = me.id
LEFT JOIN blog_comment blog_comments ON blog_comments.blog = blogs.id;
> You could switch to a straight join which should allow you to specify your
> columms although they would then be in the primary resultset rather than
> as
> related objects.
Can you please tell me how to do that?
Thanks.
Octavian
More information about the DBIx-Class
mailing list