[Bast-commits] r8388 - in DBIx-Class/0.08/trunk: . lib/DBIx/Class t

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Wed Jan 20 07:32:40 GMT 2010


Author: ribasushi
Date: 2010-01-20 07:32:39 +0000 (Wed, 20 Jan 2010)
New Revision: 8388

Modified:
   DBIx-Class/0.08/trunk/Changes
   DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSetColumn.pm
   DBIx-Class/0.08/trunk/t/88result_set_column.t
Log:
Fix minor RSC bug

Modified: DBIx-Class/0.08/trunk/Changes
===================================================================
--- DBIx-Class/0.08/trunk/Changes	2010-01-20 07:17:44 UTC (rev 8387)
+++ DBIx-Class/0.08/trunk/Changes	2010-01-20 07:32:39 UTC (rev 8388)
@@ -12,6 +12,8 @@
         - Stop the SQLT parser from auto-adding indexes identical to the
           Primary Key
         - Schema POD improvement for dclone
+        - Fix ResultSetColumn improperly selecting more than the requested
+          column when +columns/+select is present
         - Fix regression in context sensitiveness of deployment_statements
         - Fix regression resulting in overcomplicated query on
           search_related from prefetching resultsets

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSetColumn.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSetColumn.pm	2010-01-20 07:17:44 UTC (rev 8387)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSetColumn.pm	2010-01-20 07:32:39 UTC (rev 8388)
@@ -42,24 +42,26 @@
   my ($class, $rs, $column) = @_;
   $class = ref $class if ref $class;
 
-  $rs->throw_exception("column must be supplied") unless $column;
+  $rs->throw_exception('column must be supplied') unless $column;
 
   my $orig_attrs = $rs->_resolved_attrs;
   my $new_parent_rs = $rs->search_rs;
+  my $new_attrs = $new_parent_rs->{attrs} ||= {};
 
+  # since what we do is actually chain to the original resultset, we need to throw
+  # away all selectors (otherwise they'll chain)
+  delete $new_attrs->{$_} for (qw/columns +columns select +select as +as cols include_columns/);
+
   # prefetch causes additional columns to be fetched, but we can not just make a new
   # rs via the _resolved_attrs trick - we need to retain the separation between
   # +select/+as and select/as. At the same time we want to preserve any joins that the
   # prefetch would otherwise generate.
-
-  my $new_attrs = $new_parent_rs->{attrs} ||= {};
   $new_attrs->{join} = $rs->_merge_attr( delete $new_attrs->{join}, delete $new_attrs->{prefetch} );
 
   # If $column can be found in the 'as' list of the parent resultset, use the
   # corresponding element of its 'select' list (to keep any custom column
   # definition set up with 'select' or '+select' attrs), otherwise use $column
   # (to create a new column definition on-the-fly).
-
   my $as_list = $orig_attrs->{as} || [];
   my $select_list = $orig_attrs->{select} || [];
   my $as_index = List::Util::first { ($as_list->[$_] || "") eq $column } 0..$#$as_list;

Modified: DBIx-Class/0.08/trunk/t/88result_set_column.t
===================================================================
--- DBIx-Class/0.08/trunk/t/88result_set_column.t	2010-01-20 07:17:44 UTC (rev 8387)
+++ DBIx-Class/0.08/trunk/t/88result_set_column.t	2010-01-20 07:32:39 UTC (rev 8388)
@@ -6,6 +6,7 @@
 use Test::Exception;
 use lib qw(t/lib);
 use DBICTest;
+use DBIC::SqlMakerTest;
 
 my $schema = DBICTest->init_schema();
 
@@ -61,6 +62,16 @@
 lives_ok(sub { $psrs->get_column('count')->next }, '+select/+as additional column "count" present (scalar)');
 dies_ok(sub { $psrs->get_column('noSuchColumn')->next }, '+select/+as nonexistent column throws exception');
 
+# test +select/+as for overriding a column
+$psrs = $schema->resultset('CD')->search({},
+    {
+        'select'   => \"'The Final Countdown'",
+        'as'       => 'title'
+    }
+);
+is($psrs->get_column('title')->next, 'The Final Countdown', '+select/+as overridden column "title"');
+
+
 # test +select/+as for multiple columns
 $psrs = $schema->resultset('CD')->search({},
     {
@@ -71,15 +82,29 @@
 lives_ok(sub { $psrs->get_column('count')->next }, '+select/+as multiple additional columns, "count" column present');
 lives_ok(sub { $psrs->get_column('addedtitle')->next }, '+select/+as multiple additional columns, "addedtitle" column present');
 
-# test +select/+as for overriding a column
-$psrs = $schema->resultset('CD')->search({},
-    {
-        'select'   => \"'The Final Countdown'",
-        'as'       => 'title'
-    }
+# test that +select/+as specs do not leak
+is_same_sql_bind (
+  $psrs->get_column('year')->as_query,
+  '(SELECT me.year FROM cd me)',
+  [],
+  'Correct SQL for get_column/as'
 );
-is($psrs->get_column('title')->next, 'The Final Countdown', '+select/+as overridden column "title"');
 
+is_same_sql_bind (
+  $psrs->get_column('addedtitle')->as_query,
+  '(SELECT me.title FROM cd me)',
+  [],
+  'Correct SQL for get_column/+as col'
+);
+
+is_same_sql_bind (
+  $psrs->get_column('count')->as_query,
+  '(SELECT COUNT(*) FROM cd me)',
+  [],
+  'Correct SQL for get_column/+as func'
+);
+
+
 {
   my $rs = $schema->resultset("CD")->search({}, { prefetch => 'artist' });
   my $rsc = $rs->get_column('year');




More information about the Bast-commits mailing list