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

Jess Robinson castaway at desert-island.me.uk
Tue Jan 3 16:53:17 GMT 2012


It's hard to debug your problem with only tiny snippets of the code. =

Somewhere in your code or your template you are using the relationship =

without the columns restriction or just by calling it via the relationship =

method.

Can you reply including all the relevant bits of code, instead of just =

tiny parts?

Or start debugging by using a very minimal app or script, and find out =

yourself which piece of code is causing the SQL statements which fetch all =

the columns.

DBIC does what you ask it, mostly..

Jess


On Mon, 2 Jan 2012, Miguel Barco wrote:

> Thank you. All the pieces fit, despite I do not like the whole picture...=
 And 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 exc=
erpt:=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.longdescri=
ption1=A0the_accessor.longresume1=A0/
>
> The debug window shows the right SELECT in the first lines (from table 1 =
and from table 2). But after that, it adds all the columns of the secondary=
 (longdescription2,=A0longdescription3, etc). And they are big text fields =
and blobs!!
>
> It seems to be covered by the docs here=A0but I do not fully understand t=
he "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 develop=
er 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 togeth=
er.
>
> 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> wro=
te:
>> 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 =
the
>> relationship!!
>> - If I remove the prefetch and the TT label in the template, it ignores =
the
>> secondary.
>>
>> So Template Toolkit is calling back the relationship, forcing queries to
>> fill all the labels ??????
>>
>> I do not understand.
>>
>> Migue.
>>


More information about the DBIx-Class mailing list