[Dbix-class] Fwd: [Catalyst] Selecting from more tables(DBIC-bug?)

Carl Johnstone dbixclass at fadetoblack.me.uk
Wed Jan 20 10:36:11 GMT 2010


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.

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.

In theory you can use the columns attribute as part of the relationship 
definition eg:

__PACKAGE__->has_many{'blogs', 'MyApp::Blogs', {}, {'columns' => 
'blogs.title'}};

A quick test suggests that may not work though - which may be a bug as the 
docs say that all the standard attributes work in relationships.

Carl




More information about the DBIx-Class mailing list