[Dbix-class] Is columns to cols as +columns is to +cols

Darius Jokilehto dariusjokilehto at yahoo.co.uk
Mon Mar 18 16:44:08 GMT 2013


Just wanted to point out an issue I ran with cols/+cols when chaining a cou=
ple of DBIC queries.

I was trying to do the following:

$schema->resultset('CD')->search({}, { cols =3D> 'me.cola'})->search{}, { '=
+cols' =3D> 'me.colb' });

=A0- and was finding that 'colb' wasn't appearing in my query at all (see b=
elow test hacked from t/search/select_chain.t for details).

Had I spent a little more time reading the docs, I would have noticed that =
I made up '+cols' - there is no mention of it at all in the docs, so really=
 I should have been paying more attention and used '+columns' instead.

However, as 'cols' is a valid alias for 'columns', I made the assumption th=
at '+cols' would work for '+columns' too. I don't know why this isn't the c=
ase (is 'cols' deprecated?), but it would make sense for both keys to be ab=
breviated the same way (or warn with a deprecation notice if that's not the=
 case) and keep the behaviour consistent.

Any thoughts?


---- cut here ----
use strict;
use warnings;

use Test::More;

use lib qw(t/lib);
use DBIC::SqlMakerTest;
use DBICTest;

my $schema =3D DBICTest->init_schema();

my @chain =3D (
=A0 { columns =3D> 'me.moar_stuff' } =3D> 'SELECT me.moar_stuff FROM cd me',
=A0 { '+columns'=A0 =3D> 'me.genreid' } =3D> 'SELECT me.moar_stuff, me.genr=
eid FROM cd me',

=A0 { cols =3D> 'me.moar_stuff' } =3D> 'SELECT me.moar_stuff FROM cd me',
=A0 { '+cols'=A0 =3D> 'me.genreid' } =3D> 'SELECT me.moar_stuff, me.genreid=
 FROM cd me',


my $rs =3D $schema->resultset('CD');

my $testno =3D 1;
while (@chain) {
=A0 my $attrs =3D shift @chain;
=A0 my $sql =3D shift @chain;

=A0 $rs =3D $rs->search ({}, $attrs)->search({}, shift @chain);
=A0 $sql =3D shift @chain;

=A0 is_same_sql_bind (
=A0=A0=A0 $rs->as_query,
=A0=A0=A0 "($sql)",
=A0=A0=A0 [],
=A0=A0=A0 "Test $testno of SELECT assembly ok",
=A0 );

=A0 $testno++;


---- cut here ----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20130318/cbd=

More information about the DBIx-Class mailing list