[Dbix-class] Help with Problem with Distinct

neil.lunn at trixan.com neil.lunn at trixan.com
Tue Feb 19 12:34:39 GMT 2008




I write the following structure in full. The problem I am having is
that any other combination of 'distinct' as shown in the commented parts
throws an error. What am I missing?

The SQL subselect is there
simply because I can see no other way to implement it.

my $rs =3D
$schema->resultset('Inventorycategorymap')->search(
=A0 {
=A0=A0=A0 # Selection
=A0=A0=A0 '-and' =3D> [
=A0=A0=A0=A0=A0 '-or' =3D> [
=A0=A0=A0=A0=A0=A0=A0 'c2p.parentcategoryid' =3D>
{'<>',463},
=A0=A0=A0=A0=A0=A0=A0
'm2.inventorycategoryid' =3D> 468,
=A0=A0=A0=A0=A0
],
=A0=A0=A0=A0=A0 '-or' =3D> [
=A0=A0=A0=A0=A0=A0=A0 'c2p.parentcategoryid' =3D>
{'<>',716},
=A0=A0=A0=A0=A0=A0=A0
'm2.inventorycategoryid' =3D> 722,
=A0=A0=A0=A0=A0
],
=A0=A0=A0 ],
=A0 },
=A0 {
=A0=A0=A0 alias =3D> 'm2',
=A0=A0=A0 from=A0
=3D> [
=A0=A0=A0=A0=A0 { 'm2' =3D>
'inventorycategorymap' },
=A0=A0=A0=A0=A0 [
=A0=A0=A0=A0=A0=A0=A0 { 'myii' =3D>
=A0=A0=A0=A0=A0=A0=A0=A0=A0 '(select i.id
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0
from inventorycategorymap icm
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0
join inventorycategories ic on ic.id =3D icm.inventorycategoryid
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0
join inventoryitems i on i.id =3D icm.inventoryitemid
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0
where ic.id =3D 715 or ic.id =3D 468 or ic.id =3D 722
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0
group by i.id
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0
having count(*) =3D 3)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 '
=A0=A0=A0=A0=A0=A0=A0 },
=A0=A0=A0=A0=A0=A0=A0 { 'myii.id' =3D>
'm2.inventoryitemid' },
=A0=A0=A0=A0=A0 ],
=A0=A0=A0=A0=A0 [
=A0=A0=A0=A0=A0=A0=A0 { 'c2' =3D>
'inventorycategories' },
=A0=A0=A0=A0=A0=A0=A0 {
'c2.id' =3D> 'm2.inventorycategoryid' },
=A0=A0=A0=A0=A0 ],
=A0=A0=A0=A0=A0
[
=A0=A0=A0=A0=A0=A0=A0 { 'c2p' =3D>
'inventorycategories' },
=A0=A0=A0=A0=A0=A0=A0 {
'c2.parentcategoryid' =3D> 'c2p.id' }
=A0=A0=A0=A0=A0
],
=A0=A0=A0 ],
=A0=A0=A0 'select' =3D> [ {
distinct =3D> [ 'm2.inventorycategoryid' ] } ],
=A0=A0=A0
'as' =3D> [ 'inventorycategoryid' ],
#=A0=A0 'select' =3D> [
{ distinct =3D> [ 'm2.inventorycategoryid', 'c2.name' ] } ],
#=A0=A0 'select' =3D> [ 'inventorycategoryid', 'c2.name' ],
#=A0=A0 'as'=A0=A0=A0=A0 =3D> [
'inventorycategoryid', 'inventorycategories.name' ],
=A0=A0=A0 'order_by' =3D> 'c2p.name, c2.name',
=A0
},
);

Neil

=A0





More information about the DBIx-Class mailing list