[Dbix-class] Re: Prefetch and join on different tables

Dagfinn Ilmari Mannsåker ilmari at ilmari.org
Mon Jan 21 20:35:14 GMT 2013


Paula <mpmagarinos at gmail.com> writes:

> I really don't understand why this happens...
>
> If the search is:
> my $rs1 = $c->model('weight::Mdata')->search($where,$attr,{prefetch =>
> 'mc'},{join =>'mt'});
> The DBIC TRACE shows that the join occurs between mdata and mt, and I get
> the following error:
> [error] DBIx::Class::ResultSet::next(): DBI Exception: DBD::mysql::st
> execute failed: Unknown column 'mc.h1' in 'where clause'

All the attributes need to go in the second argument to ->search:

->search($where, { %{$attr}, prefetch => 'mc', join => 'mt' });

Note that this will override any prefetch or join supplied in $attr.

> Inversely, if the search is:
> my $rs1 = $c->model('weight::Mdata')->search($where,$attr,{join
> =>'mt'},{prefetch => 'mc'});
> The DBIC TRACE shows that the join (and the prefetch) occurs between mdata
> and mc, and I get the following error:
> [error] DBIx::Class::ResultSet::next(): DBI Exception: DBD::mysql::st
> execute failed: Unknown column 'mt.n_C' in 'where clause'
>
> It seems as the prefetch 'erases' the join and viceversa...
>
>
> 2013/1/21 Paula <mpmagarinos at gmail.com>
>
>> Hi! Thank you for your answer. Unfortunately neither of the 2
>> possibilities work. In both cases I get the same error:
>> [error] DBIx::Class::Row::get_column(): No such column 'h1'
>>
>>
>> 2013/1/18 Patrick Meidl <pmeidl at ist.ac.at>
>>
>>> On Fri, Jan 18 2013, mpm <mpmagarinos at gmail.com> wrote:
>>>
>>> > push @{ $attr->{join} }, 'mt';
>>> > push @{ $attr->{join} }, 'mc';
>>> > my $rs1 = $c->model('weight::Mdata')->search( $where, $attr,{prefetch =>
>>> > 'mc'});
>>>
>>> I think your curly braces are misplaced. this should do what you want:
>>>
>>> my $rs1 = $c->model('weight::Mdata')->search($where,
>>>     { %$attr, prefetch => 'mc' });
>>>
>>> or alternatively:
>>>
>>> push @{ $attr->{join} }, 'mt';
>>> push @{ $attr->{join} }, 'mc';
>>> $attr->{prefetch} = 'mc';
>>> my $rs1 = $c->model('weight::Mdata')->search($where, $attr);
>>>
>>>
>>> HTH
>>>
>>>     patrick
>>>
>>> --
>>> Patrick Meidl, Mag.
>>> Senior Expert Software Engineering
>>>
>>> IST - Institute of Science and Technology Austria
>>> Am Campus 1
>>> A-3400 Klosterneuburg, Austria
>>>
>>> R 03.EG.003
>>> T +43 2243 9000 1063
>>> E pmeidl at ist.ac.at
>>> W http://www.ist.ac.at/
>>>
>>>
>>> _______________________________________________
>>> 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/dbix-class@lists.scsys.co.uk
>>>
>>
>>

-- 
"A disappointingly low fraction of the human race is,
 at any given time, on fire." - Stig Sandbeck Mathisen




More information about the DBIx-Class mailing list