[Dbix-class] Re: Best possible way to retrieve data using relationship

linuxsupport lin.support at gmail.com
Fri Dec 31 14:41:15 GMT 2010


Thanks Peter,

That means when I have to get columns from multiple tables I could use join
and select those column correct?
Or are you saying that I should not use join like this and use different
approach?
Basically I have to fetch data from multiple table to show one article.

That is why I posted here to find best way to retrieve data from multiple
related tables.

Thanks


On Fri, Dec 31, 2010 at 7:47 PM, Peter Rabbitson
<rabbit+dbic at rabbit.us<rabbit%2Bdbic at rabbit.us>
> wrote:

> linuxsupport wrote:
>
>> Thanks for the reply.
>>
>> I have something like
>>
>> my $rs =3D $schema->resultset('Article')->search(
>> {
>>   "me.id <http://me.id>" =3D> 1
>>
>> },
>> {
>>    join =3D> [
>>               {arti_author =3D> "author"},
>>               {arti_comnt =3D> "comments"},
>>              ],
>>     select =3D> [
>>                 qw/ me.create_date author.author_name comments.comment
>> comments.comment_date comments.name <http://comments.name> /
>>
>>                  ],
>>       as =3D> [
>>                  qw/ created author comment comment_date commented_by /
>>                 ]
>> }
>> );
>>         How can I use prefetch to simplify it?
>>
>>
> You can't - prefetch is something that you use when you need complete
> related (but distinct) result objects fetched at once. What you are doing
> instead is abandoning the strict separation and mixing data from several
> sources into one data object (which kinda defeats part of the purpose of
> DBIC). So no - you can not use prefetch here, as it has a different
> design endgoal.
>
> My advice is to stop thinking in SQL (I have N tables from which I retrie=
ve
> M columns) and instead think in interrelated row objects. When you do in
> fact run across a bottleneck - we'll be happy to help you optimize a
> particular query, but doing what you show above as a general rule is
> largely
> missing the point of DBIC.
>
> Hope this helps, cheers!
>
>
> _______________________________________________
> 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/dbix-class@lists.scsys.co.uk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20101231/a6b=
539ce/attachment.htm


More information about the DBIx-Class mailing list