[Bast-commits] r3958 - in
DBIx-Class/0.09/branches/find_unique_fallback: .
lib/DBIx/Class t t/lib/DBICTest/Schema
dwc at dev.catalyst.perl.org
dwc at dev.catalyst.perl.org
Mon Jan 21 22:58:56 GMT 2008
Author: dwc
Date: 2008-01-21 22:58:56 +0000 (Mon, 21 Jan 2008)
New Revision: 3958
Modified:
DBIx-Class/0.09/branches/find_unique_fallback/Changes
DBIx-Class/0.09/branches/find_unique_fallback/lib/DBIx/Class/ResultSet.pm
DBIx-Class/0.09/branches/find_unique_fallback/t/101populate_rs.t
DBIx-Class/0.09/branches/find_unique_fallback/t/lib/DBICTest/Schema/Artist.pm
DBIx-Class/0.09/branches/find_unique_fallback/t/lib/DBICTest/Schema/BooksInLibrary.pm
DBIx-Class/0.09/branches/find_unique_fallback/t/lib/DBICTest/Schema/Owners.pm
Log:
Rework _is_unique_query check a little to better handle the where attr
Modified: DBIx-Class/0.09/branches/find_unique_fallback/Changes
===================================================================
--- DBIx-Class/0.09/branches/find_unique_fallback/Changes 2008-01-21 22:55:08 UTC (rev 3957)
+++ DBIx-Class/0.09/branches/find_unique_fallback/Changes 2008-01-21 22:58:56 UTC (rev 3958)
@@ -6,6 +6,8 @@
context; this makes things like func('DISTINCT') work as expected
- Many-to-many relationships now warn if the utility methods would
clash
+ - Remove _collapse_query in favor of _collapse_cond in ::ResultSet
+ - Restore _is_unique_query check in ::ResultSet
0.08007 2007-09-04 19:36:00
- patch for Oracle datetime inflation (abram at arin.net)
Modified: DBIx-Class/0.09/branches/find_unique_fallback/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.09/branches/find_unique_fallback/lib/DBIx/Class/ResultSet.pm 2008-01-21 22:55:08 UTC (rev 3957)
+++ DBIx-Class/0.09/branches/find_unique_fallback/lib/DBIx/Class/ResultSet.pm 2008-01-21 22:58:56 UTC (rev 3958)
@@ -539,11 +539,10 @@
}
}
-# XXX: Disabled since it doesn't infer uniqueness in all cases
-# unless ($self->_is_unique_query($attrs->{where})) {
-# carp "Query not guaranteed to return a single row"
-# . "; please declare your unique constraints or use search instead";
-# }
+ unless ($self->_is_unique_query($attrs->{where})) {
+ carp "Query not guaranteed to return a single row"
+ . "; please declare your unique constraints or use search instead";
+ }
my @data = $self->result_source->storage->select_single(
$attrs->{from}, $attrs->{select},
@@ -561,7 +560,8 @@
sub _is_unique_query {
my ($self, $query) = @_;
- my $collapsed = $self->_collapse_query($query);
+ my $collapsed = $self->_collapse_cond($query);
+# use Data::Dumper; warn Dumper $query, $collapsed;
my $alias = $self->{attrs}{alias};
foreach my $name ($self->result_source->unique_constraint_names) {
@@ -575,7 +575,7 @@
foreach my $key (keys %$collapsed) {
my $aliased = $key =~ /\./ ? $key : "$alias.$key";
next unless exists $seen{$aliased}; # Additional constraints are okay
- $seen{$aliased} = scalar keys %{ $collapsed->{$key} };
+ $seen{$aliased}++;
}
# If we get 0 or more than 1 value for a column, it's not necessarily unique
@@ -585,41 +585,6 @@
return 0;
}
-# _collapse_query
-#
-# Recursively collapse the query, accumulating values for each column.
-
-sub _collapse_query {
- my ($self, $query, $collapsed) = @_;
-
- $collapsed ||= {};
-
- if (ref $query eq 'ARRAY') {
- foreach my $subquery (@$query) {
- next unless ref $subquery; # -or
-# warn "ARRAY: " . Dumper $subquery;
- $collapsed = $self->_collapse_query($subquery, $collapsed);
- }
- }
- elsif (ref $query eq 'HASH') {
- if (keys %$query and (keys %$query)[0] eq '-and') {
- foreach my $subquery (@{$query->{-and}}) {
-# warn "HASH: " . Dumper $subquery;
- $collapsed = $self->_collapse_query($subquery, $collapsed);
- }
- }
- else {
-# warn "LEAF: " . Dumper $query;
- foreach my $col (keys %$query) {
- my $value = $query->{$col};
- $collapsed->{$col}{$value}++;
- }
- }
- }
-
- return $collapsed;
-}
-
=head2 get_column
=over 4
Modified: DBIx-Class/0.09/branches/find_unique_fallback/t/101populate_rs.t
===================================================================
--- DBIx-Class/0.09/branches/find_unique_fallback/t/101populate_rs.t 2008-01-21 22:55:08 UTC (rev 3957)
+++ DBIx-Class/0.09/branches/find_unique_fallback/t/101populate_rs.t 2008-01-21 22:58:56 UTC (rev 3958)
@@ -313,12 +313,12 @@
{
title => 'Some CD3',
year => '1997',
- artist => { artistid=> ++$aid, name => 'Fred BloggsC'},
+ artist => { artistid=> ++$aid, name => 'Fred BloggsE'},
},
{
title => 'Some CD4',
year => '1997',
- artist => { artistid=> ++$aid, name => 'Fred BloggsD'},
+ artist => { artistid=> ++$aid, name => 'Fred BloggsF'},
},
];
@@ -326,11 +326,11 @@
isa_ok($cdA, 'DBICTest::CD', 'Created CD');
isa_ok($cdA->artist, 'DBICTest::Artist', 'Set Artist');
- is($cdA->artist->name, 'Fred BloggsC', 'Set Artist to FredC');
+ is($cdA->artist->name, 'Fred BloggsE', 'Set Artist to FredE');
isa_ok($cdB, 'DBICTest::CD', 'Created CD');
isa_ok($cdB->artist, 'DBICTest::Artist', 'Set Artist');
- is($cdB->artist->name, 'Fred BloggsD', 'Set Artist to FredD');
+ is($cdB->artist->name, 'Fred BloggsF', 'Set Artist to FredF');
ok($cdB->artist->artistid == $aid, "Got Expected Artist ID");
}
}
@@ -601,4 +601,4 @@
ok( $cd2->title eq "VOID_Yet More Tweeny-Pop crap", "Got Expected CD Title");
}
-}
\ No newline at end of file
+}
Modified: DBIx-Class/0.09/branches/find_unique_fallback/t/lib/DBICTest/Schema/Artist.pm
===================================================================
--- DBIx-Class/0.09/branches/find_unique_fallback/t/lib/DBICTest/Schema/Artist.pm 2008-01-21 22:55:08 UTC (rev 3957)
+++ DBIx-Class/0.09/branches/find_unique_fallback/t/lib/DBICTest/Schema/Artist.pm 2008-01-21 22:58:56 UTC (rev 3958)
@@ -21,6 +21,7 @@
},
);
__PACKAGE__->set_primary_key('artistid');
+__PACKAGE__->add_unique_constraint([ qw/name/ ]);
__PACKAGE__->mk_classdata('field_name_for', {
artistid => 'primary key',
Modified: DBIx-Class/0.09/branches/find_unique_fallback/t/lib/DBICTest/Schema/BooksInLibrary.pm
===================================================================
--- DBIx-Class/0.09/branches/find_unique_fallback/t/lib/DBICTest/Schema/BooksInLibrary.pm 2008-01-21 22:55:08 UTC (rev 3957)
+++ DBIx-Class/0.09/branches/find_unique_fallback/t/lib/DBICTest/Schema/BooksInLibrary.pm 2008-01-21 22:58:56 UTC (rev 3958)
@@ -22,6 +22,7 @@
},
);
__PACKAGE__->set_primary_key('id');
+__PACKAGE__->add_unique_constraint([ qw/owner title/ ]);
__PACKAGE__->resultset_attributes({where => { source => "Library" } });
Modified: DBIx-Class/0.09/branches/find_unique_fallback/t/lib/DBICTest/Schema/Owners.pm
===================================================================
--- DBIx-Class/0.09/branches/find_unique_fallback/t/lib/DBICTest/Schema/Owners.pm 2008-01-21 22:55:08 UTC (rev 3957)
+++ DBIx-Class/0.09/branches/find_unique_fallback/t/lib/DBICTest/Schema/Owners.pm 2008-01-21 22:58:56 UTC (rev 3958)
@@ -15,6 +15,7 @@
},
);
__PACKAGE__->set_primary_key('ownerid');
+__PACKAGE__->add_unique_constraint([ qw/name/ ]);
__PACKAGE__->has_many(books => "DBICTest::Schema::BooksInLibrary", "owner");
More information about the Bast-commits
mailing list