Hi, it seems to be a bug, but maybe I just overlooked something: if I chain two searches that contain '+select' (and/or '+as') attributes, then the column list of the second search() overwrites the column list of the first.
For example:
# using the schema of the DBIC manual
# (see attached file chaining_problem.tbz)
$schema->resultset('Artist')->search(
{
},
{
'+select' => [ \'1' ],
'+as' => [ 'one' ],
}
)->search(
{
},
{
'+select' => [ \'2' ],
'+as' => [ 'two' ],
}
)->first;
This generates this SQL query:
SELECT me.artistid, me.name, 2 FROM artist me
Instead of what I expected:
SELECT me.artistid, me.name, 1, 2 FROM artist me
I tried to create at least a test for that (see the attached diff). In
fact there's another issue with 88result_set_column.t: for me it seems
that $psrs->get_column() returns a DBIx::Class::ResultSetColumn object
even if no column exists with that name, so all the '+select/+as' tests
are kind of useless.. :-( I added a test for that bug, too ('+select/+as
nonexistent_column'). Currently that other bug/feature masks the tests
for my original problem.
Can you confirm if it's really a bug? (Or what was that I overlooked?)
Perl: v5.8.8 built for i486-linux-gnu-thread-multi
DBIx::Class: 0.08010
SQL::Abstract: 1.21
norbi
--- DBIx-Class-0.08010/t/88result_set_column.t 2007-10-03 20:30:56.000000000 +0200
+++ DBIx-Class-0.08010-fixed/t/88result_set_column.t 2008-10-09 12:26:35.000000000 +0200
@@ -7,7 +7,7 @@
my $schema = DBICTest->init_schema();
-plan tests => 10;
+plan tests => 13;
my $cd;
my $rs = $cd = $schema->resultset("CD")->search({});
@@ -34,6 +34,23 @@
}
);
ok(defined($psrs->get_column('count')), '+select/+as count');
+my $nonexistent_column;
+eval { $nonexistent_column = $psrs->get_column('nonexistent_column'); };
+ok(!defined($nonexistent_column), '+select/+as nonexistent_column');
+
+$psrs = $schema->resultset('CD')->search({},
+ {
+ '+select' => \'COUNT(*)',
+ '+as' => 'count'
+ }
+)->search({},
+ {
+ '+select' => 'title',
+ '+as' => 'addedtitle'
+ }
+);
+ok(defined($psrs->get_column('count')), '+select/+as chained count');
+ok(defined($psrs->get_column('addedtitle')), '+select/+as chained title');
$psrs = $schema->resultset('CD')->search({},
{
chaining_problem.tbz
Description: application/bzip-compressed-tar
_______________________________________________ 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/[email protected]
