[Dbix-class] DBIx::Class::Helpers -- UNION query with mixed column
names
Bill Moseley
moseley at hank.org
Fri Jun 21 05:26:41 GMT 2013
Looking at the example here:
http://search.cpan.org/~frew/DBIx-Class-Helpers-2.017000/lib/DBIx/Class/Hel=
per/ResultSet/SetOperations.pm#DESCRIPTION
This works because the column names are the same. Notice how both tables
use "id" as the key.
my $rs1 =3D $schema->resultset('Album')->search({
name =3D> { -like =3D> "$input%" }
}, {
columns =3D> [qw( id name ), {
tablename =3D> \['?', [{} =3D> 'album']],
}],
});
my $rs2 =3D $schema->resultset('Artist')->search({
name =3D> { -like =3D> "$input%" }
}, {
columns =3D> [qw( id name ), {
tablename =3D> \['?', [{} =3D> 'artist']],
}],
});
I have a similar situation, but unfortunately, my column names are
"album_id" and "artist_id" so that will fail because the column names are
not the same.
Is this the correct way to solve this?
my $rs1 =3D $schema->resultset('Album')->search({
name =3D> { -like =3D> "$input%" }
}, {
*select =3D> [ '\album_id as id', 'name', { tablename =3D> \['?', [{} =
=3D>
'album']],}],*
* as =3D> [qw( id name tablename )],*
});
my $rs2 =3D $schema->resultset('Artist')->search({
name =3D> { -like =3D> "$input%" }
}, {
*columns =3D> ['\artist_id as id', 'name', { tablename =3D> \['?', [{} =
=3D>
'artist']], }],*
* as =3D> [qw( id name tablename )],*
});
By the way, what is the advantage of the above for tablename vs. a scalar
reference? i.e. '\artist as tablename'
-- =
Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20130620/96c=
51bd6/attachment.htm
More information about the DBIx-Class
mailing list