[Dbix-class] I get only one in a one to one
Nigel Metheringham
nigel at dotdot.it
Sun Jan 1 19:36:14 GMT 2012
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 ------------------------------ nigel at dotdot.it ]
[ Ellipsis Intangible Technologies ]
More information about the DBIx-Class
mailing list