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

Darius Jokilehto dariusjokilehto at yahoo.co.uk
Mon Mar 18 17:54:53 GMT 2013


Hello,

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

I was trying to do the following:

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

 - and was finding that 'colb' wasn't appearing in my query at all (see 
below 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 that '+cols' would work for '+columns' too. I don't know why this isn't the case (is 'cols' deprecated?), but it would make sense for both keys to be abbreviated the same way (or warn with a deprecation notice if that's not the case) and keep the behaviour consistent.

Any thoughts?

Darius

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

use Test::More;

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

my $schema = DBICTest->init_schema();

my @chain = (
  { columns => 'me.moar_stuff' } => 'SELECT me.moar_stuff FROM cd me',
  { '+columns'  => 'me.genreid' } => 'SELECT me.moar_stuff, me.genreid FROM cd me',

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

);

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

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

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

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

  $testno++;
}

done_testing;
---- cut here ----



More information about the DBIx-Class mailing list