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?


---- 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 

  { 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 (
    "Test $testno of SELECT assembly ok",



---- cut here ----
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

Reply via email to