[Bast-commits] r7598 - in DBIx-Class/0.08/trunk: lib/DBIx/Class t
t/lib/DBICTest/Schema
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Mon Sep 7 14:46:14 GMT 2009
Author: ribasushi
Date: 2009-09-07 14:46:14 +0000 (Mon, 07 Sep 2009)
New Revision: 7598
Modified:
DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
DBIx-Class/0.08/trunk/t/80unique.t
DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Artist.pm
Log:
Prune duplicate constraints from the find() condition
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm 2009-09-07 14:26:59 UTC (rev 7597)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm 2009-09-07 14:46:14 UTC (rev 7598)
@@ -570,12 +570,16 @@
my $where = $self->_collapse_cond($self->{attrs}{where} || {});
my $num_where = scalar keys %$where;
- my @unique_queries;
+ my (@unique_queries, %seen_column_combinations);
foreach my $name (@constraint_names) {
- my @unique_cols = $self->result_source->unique_constraint_columns($name);
- my $unique_query = $self->_build_unique_query($query, \@unique_cols);
+ my @constraint_cols = $self->result_source->unique_constraint_columns($name);
- my $num_cols = scalar @unique_cols;
+ my $constraint_sig = join "\x00", sort @constraint_cols;
+ next if $seen_column_combinations{$constraint_sig}++;
+
+ my $unique_query = $self->_build_unique_query($query, \@constraint_cols);
+
+ my $num_cols = scalar @constraint_cols;
my $num_query = scalar keys %$unique_query;
my $total = $num_query + $num_where;
Modified: DBIx-Class/0.08/trunk/t/80unique.t
===================================================================
--- DBIx-Class/0.08/trunk/t/80unique.t 2009-09-07 14:26:59 UTC (rev 7597)
+++ DBIx-Class/0.08/trunk/t/80unique.t 2009-09-07 14:46:14 UTC (rev 7598)
@@ -1,14 +1,14 @@
use strict;
-use warnings;
+use warnings;
use Test::More;
use lib qw(t/lib);
use DBICTest;
+use DBIC::SqlMakerTest;
+use DBIC::DebugObj;
my $schema = DBICTest->init_schema();
-plan tests => 49;
-
# Check the defined unique constraints
is_deeply(
[ sort $schema->source('CD')->unique_constraint_names ],
@@ -209,4 +209,27 @@
);
ok($cd2->in_storage, 'Updating year using update_or_new was successful');
is($cd2->id, $cd1->id, 'Got the same CD using update_or_new');
-}
\ No newline at end of file
+}
+
+# make sure the ident condition is assembled sanely
+{
+ my $artist = $schema->resultset('Artist')->next;
+
+ my ($sql, @bind);
+ $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)),
+ $schema->storage->debug(1);
+
+ $artist->discard_changes;
+
+ is_same_sql_bind (
+ $sql,
+ \@bind,
+ 'SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me WHERE me.artistid = ?',
+ [qw/'1'/],
+ );
+
+ $schema->storage->debug(0);
+ $schema->storage->debugobj(undef);
+}
+
+done_testing;
Modified: DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Artist.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Artist.pm 2009-09-07 14:26:59 UTC (rev 7597)
+++ DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Artist.pm 2009-09-07 14:46:14 UTC (rev 7598)
@@ -30,6 +30,7 @@
},
);
__PACKAGE__->set_primary_key('artistid');
+__PACKAGE__->add_unique_constraint(['artistid']); # do not remove, part of a test
__PACKAGE__->mk_classdata('field_name_for', {
artistid => 'primary key',
More information about the Bast-commits
mailing list