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

Miguel Barco miguelelelele at yahoo.es
Sun Jan 1 23:03:47 GMT 2012


Thank you!, now I can get all data. But the problem now is that I have noti=
ced that the relationship is always present, even when I want to retrieve j=
ust columns from the main table.

After a query without prefetch, it hits the database with a "SELECT from th=
e secondary table" for each one of the rows found from the primary table.

=BFCan it be avoided, or I need to make another schema without relationship=
s?

Regards:
Migue.



________________________________
 De: Nigel Metheringham <nigel at dotdot.it>
Para: Miguel Barco <miguelelelele at yahoo.es>; DBIx::Class user and developer=
 list <dbix-class at lists.scsys.co.uk> =

Enviado: domingo 1 de enero de 2012 20:36
Asunto: Re: [Dbix-class] I get only one in a one to one
 =


On 1 Jan 2012, at 19:02, Miguel Barco wrote:

> return $self->search(the_main_query_to_search_the_main_rows)->search_rela=
ted(the_has_one_accessor)
> =

> The query retrieves just the expected rows (using columns of the first ta=
ble for WHERE and ORDER). But the SELECT only contains the columns and data=
 from the related, secondary table!!!! Nothing from the first one.

Thats basically what you would expect - if you want joined items then you n=
eed to add a join/prefetch into the search attributes.

Which would make the code look like:-

=A0 return $self->search({the_main_query_to_search_the_main_rows},
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0  {prefetch=3D>' the_has_one_acc=
essor'});


=A0 https://metacpan.org/module/DBIx::Class::ResultSet#prefetch
=A0 https://metacpan.org/module/DBIx::Class::Manual::Cookbook#Using-joins-a=
nd-prefetch



=A0=A0=A0 Nigel.
--
[ Nigel Metheringham ------------------------------ nigel at dotdot.it ]
[=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0  Ellipsis Intangible Technologies=A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 ]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120101/f5d=
ee1a7/attachment.htm


More information about the DBIx-Class mailing list