[Dbix-class] I get only one in a one to one

Miguel Barco miguelelelele at yahoo.es
Mon Jan 2 21:46:10 GMT 2012


Thank you. All the pieces fit, despite I do not like the whole picture... A=
nd it reveals an additional problem:

- The secondary, prefetched table, is always retrieving all the columns.

- I am using "columns =3D> [@the_columns]" to select them, as is this excer=
pt:=A0
-For easy queries to the main table I have:

@the_columns =3D qw / id name color / =A0

- And I have added the needed columns from the secondary table

@=A0the_columns=A0=3D qw / me.id me.name me.color the_accessor.longdescript=
ion1=A0the_accessor.longresume1=A0/

The debug window shows the right SELECT in the first lines (from table 1 an=
d from table 2). But after that, it adds all the columns of the secondary (=
longdescription2,=A0longdescription3, etc). And they are big text fields an=
d blobs!!

It seems to be covered by the docs here=A0but I do not fully understand the=
 "implicit" behavior that it talks about.

Regards:
Migue.


________________________________
 De: Ben Tilly <btilly at gmail.com>
Para: Miguel Barco <miguelelelele at yahoo.es>; DBIx::Class user and developer=
 list <dbix-class at lists.scsys.co.uk> =

Enviado: lunes 2 de enero de 2012 18:24
Asunto: Re: [Dbix-class] I get only one in a one to one
 =

You have stated all of the relevant facts, you just need to put it together.

When you prefetch, the SELECT adds a join to pull in the dependent
table in one fetch.=A0 When you don't prefetch, it remembers the
relationship, but only calls it at need.=A0 Therefore:

- When you prefetch, it hits database just once (but it is a heavier
hit to the database)

- If you remove prefetch, every row needs the relationship and it has
to SELECT each time to get it

- If you remove prefetch and the template, you don't need the
relationship, and there is no excess SELECTing.

On Mon, Jan 2, 2012 at 2:17 AM, Miguel Barco <miguelelelele at yahoo.es> wrote:
> Wow!! It comes from the TT template!!!!
>
> I have TT labels to print data form the secondary table [%
> rsobject.relationship.column %]
>
> - When I prefetch, it hits database just once and data goes to its place =
in
> the template.
> - If I remove prefetch, it makes a SELECT for all the rows, looking for t=
he
> relationship!!
> - If I remove the prefetch and the TT label in the template, it ignores t=
he
> secondary.
>
> So Template Toolkit is calling back the relationship, forcing queries to
> fill all the labels ??????
>
> I do not understand.
>
> Migue.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120102/fcc=
f83e1/attachment.htm


More information about the DBIx-Class mailing list