[Dbix-class] Prefetch and join on different tables

Paula mpmagarinos at gmail.com
Mon Jan 21 20:15:50 GMT 2013


I really don't understand why this happens...

If the search is:
my $rs1 =3D $c->model('weight::Mdata')->search($where,$attr,{prefetch =3D>
'mc'},{join =3D>'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'

Inversely, if the search is:
my $rs1 =3D $c->model('weight::Mdata')->search($where,$attr,{join
=3D>'mt'},{prefetch =3D> '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 =3D $c->model('weight::Mdata')->search( $where, $attr,{prefetc=
h =3D>
>> > 'mc'});
>>
>> I think your curly braces are misplaced. this should do what you want:
>>
>> my $rs1 =3D $c->model('weight::Mdata')->search($where,
>>     { %$attr, prefetch =3D> 'mc' });
>>
>> or alternatively:
>>
>> push @{ $attr->{join} }, 'mt';
>> push @{ $attr->{join} }, 'mc';
>> $attr->{prefetch} =3D 'mc';
>> my $rs1 =3D $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
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20130121/046=
4c322/attachment.htm


More information about the DBIx-Class mailing list