Thank you!, now I can get all data. But the problem now is that I have noticed
that the relationship is always present, even when I want to retrieve just
columns from the main table.
After a query without prefetch, it hits the database with a "SELECT from the
secondary table" for each one of the rows found from the primary table.
¿Can it be avoided, or I need to make another schema without relationships?
Regards:
Migue.
________________________________
De: Nigel Metheringham <[email protected]>
Para: Miguel Barco <[email protected]>; DBIx::Class user and developer
list <[email protected]>
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_related(the_has_one_accessor)
>
> The query retrieves just the expected rows (using columns of the first table
> 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 need
to add a join/prefetch into the search attributes.
Which would make the code look like:-
return $self->search({the_main_query_to_search_the_main_rows},
{prefetch=>' the_has_one_accessor'});
https://metacpan.org/module/DBIx::Class::ResultSet#prefetch
https://metacpan.org/module/DBIx::Class::Manual::Cookbook#Using-joins-and-prefetch
Nigel.
--
[ Nigel Metheringham ------------------------------ [email protected] ]
[ Ellipsis Intangible Technologies ]_______________________________________________
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/[email protected]