From: "Carl Johnstone" <[email protected]>
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


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to