[Dbix-class] don't want to hit the db again

Kevin Karabian kkarabian at turnitin.com
Tue Apr 28 22:37:42 GMT 2015


Yes, but the problem is for a has_many, prefetch causes multiple rows to be
returned.  For example if a result object has 10 related objects then 10
rows are returned for that one object.  If the result object is large, then
that is a lot of repetition.  I want to basically run a query that will
return only the 10 related objects and then put those into the result
object eliminating the repetition.

And actually my use case is that I want to do this for a large number or
result objects so I am amortizing the cost by grabbing all the related
objects for all the result objects in question.  So say, I have 10 objects
and each has 10 related objects.  I get the 100 related objects at once and
populate the result objects with the relationship data.

On Tue, Apr 28, 2015 at 3:27 PM, Dagfinn Ilmari Mannsåker <ilmari at ilmari.org
> wrote:

> Kevin Karabian <kkarabian at turnitin.com> writes:
>
> > Hi,
> >
> > Is there a way to store already retrieved related objects (related as a
> > has_many) in a result object, such that calling the accessor for that
> > relationship data will not hit the db again.
>
> This is exactly what prefetch is for.
>
> https://metacpan.org/pod/DBIx::Class::ResultSet#prefetch
> https://metacpan.org/pod/DBIx::Class::ResultSet#PREFETCHING
>
> --
> - Twitter seems more influential [than blogs] in the 'gets reported in
>   the mainstream press' sense at least.               - Matt McLeod
> - That'd be because the content of a tweet is easier to condense down
>   to a mainstream media article.                      - Calle Dybedahl
>
>
> _______________________________________________
> 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
>



-- 




*Kevin KarabianSenior EngineerTurnitin – www.turnitin.com
<http://www.turnitin.com/>kkarabian at turnitin.com
<jdoe at turnitin.com>510.764.7529*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20150428/7a05e90d/attachment.htm>


More information about the DBIx-Class mailing list