Merge 'DBIx-Class-current' into 'find_compat'
Daniel Westermann-Clark [Thu, 25 May 2006 19:19:39 +0000 (19:19 +0000)]
r9296@fortuna (orig r1806):  bluefeet | 2006-05-25 12:16:28 -0400
Added TODO about changes to the rows attribute.
r9298@fortuna (orig r1808):  bluefeet | 2006-05-25 12:53:55 -0400
 r1808@moss (orig r1807):  jguenther | 2006-05-25 09:53:12 -0700
 Changed txn_do docs/Cookbook example to use closures, and made their content more consistent

r9300@fortuna (orig r1810):  bluefeet | 2006-05-25 13:04:25 -0400
 r1655@moss (orig r1654):  bluefeet | 2006-05-17 20:58:32 -0700
 Removed BasicRels and reorganized where the various init/setup code resides.

r9302@fortuna (orig r1812):  matthewt | 2006-05-25 14:19:21 -0400
piss off
r9303@fortuna (orig r1813):  bluefeet | 2006-05-25 14:24:20 -0400
 r1656@moss (orig r1655):  bluefeet | 2006-05-17 22:15:24 -0700
 Delete basicrels tests. Modify run tests to use new syntax.  Remove helperrels test wrappers.

r9305@fortuna (orig r1815):  bluefeet | 2006-05-25 14:34:59 -0400
Delete t/run/ and t/helperrels/ so that the reorganize_tests branch can merge in easly.
r9306@fortuna (orig r1816):  bluefeet | 2006-05-25 14:35:46 -0400
 r1657@moss (orig r1656):  bluefeet | 2006-05-17 22:28:10 -0700
 Move helperrels/26sqlt.t, and all t/run/*.tl scripts, to t/*.t

r9307@fortuna (orig r1817):  bluefeet | 2006-05-25 14:36:02 -0400
 r1658@moss (orig r1657):  bluefeet | 2006-05-17 23:44:53 -0700
 Fixes to tests so that they pass.

r9308@fortuna (orig r1818):  bluefeet | 2006-05-25 14:36:18 -0400

r9309@fortuna (orig r1819):  bluefeet | 2006-05-25 14:36:23 -0400
 r1795@moss (orig r1794):  bluefeet | 2006-05-24 12:50:31 -0700
 Move relationships out of Relationships.pm and in to the respective classes.  Removed references to PK::Auto.

r9310@fortuna (orig r1820):  bluefeet | 2006-05-25 14:36:42 -0400
 r1796@moss (orig r1795):  bluefeet | 2006-05-24 12:52:08 -0700
 Move population code from Schema to DBICTest.

r9311@fortuna (orig r1821):  bluefeet | 2006-05-25 14:36:50 -0400

r9312@fortuna (orig r1822):  bluefeet | 2006-05-25 14:36:55 -0400
 r1799@moss (orig r1798):  bluefeet | 2006-05-24 14:53:03 -0700
 Incorporate changes in -current.

r9313@fortuna (orig r1823):  bluefeet | 2006-05-25 14:37:10 -0400

r9314@fortuna (orig r1824):  bluefeet | 2006-05-25 14:37:16 -0400

r9315@fortuna (orig r1825):  bluefeet | 2006-05-25 14:37:23 -0400

r9318@fortuna (orig r1828):  bluefeet | 2006-05-25 14:39:07 -0400
 r1828@moss (orig r1827):  bluefeet | 2006-05-25 11:38:50 -0700
 Remove basicrels, helperrels, and run on t/.

lib/DBIx/Class/ResultSet.pm

index cc0d1ef..b2fa44e 100644 (file)
@@ -6,6 +6,7 @@ use overload
         '0+'     => \&count,
         'bool'   => sub { 1; },
         fallback => 1;
+use Carp::Clan qw/^DBIx::Class/;
 use Data::Page;
 use Storable;
 use Data::Dumper;
@@ -303,7 +304,8 @@ sub find {
     @{$hash}{@cols} = @_;
   }
   elsif (@_) {
-    # For backwards compatibility
+    # Compatibility: Allow e.g. find(id => $value)
+    carp "find by key => value deprecated; please use a hashref instead";
     $hash = {@_};
   }
   else {
@@ -317,9 +319,8 @@ sub find {
   my @constraint_names = exists $attrs->{key}
     ? ($attrs->{key})
     : $self->result_source->unique_constraint_names;
-  $self->throw_exception(
-    "Can't find unless a primary key or unique constraint is defined"
-  ) unless @constraint_names;
+  carp "find now requires a primary key or unique constraint; none is defined on "
+    . $self->result_source->name unless @constraint_names;
 
   my @unique_queries;
   foreach my $name (@constraint_names) {
@@ -335,6 +336,13 @@ sub find {
     push @unique_queries, $unique_query if %$unique_query;
   }
 
+  # Compatibility: if we didn't get a unique query, take what the user provided
+  if (%$hash and not @unique_queries) {
+    carp "find now requires values for the primary key or a unique constraint"
+      . "; please use the search method instead";
+    push @unique_queries, $hash;
+  }
+
   # Handle cases where the ResultSet already defines the query
   my $query = @unique_queries ? \@unique_queries : undef;