Hi all

This is a continuation of the "patch for ResultSet::find_or_new"
thread - but it's also a subject on it's own.

It is my understanding that:

$schema->resultset("Artist")->find({name => 'Random Girl Band'}, {key
=> 'primary'});

should never find anything - because it should search by the primary
key that is not included in the search conditions.  And I believe I am
not alone in this interpretation of the documentation - see for
example Matt's words:

> The usual use of find_or_new is to pass a unique key plus additional
> attributes to be used for object creation (which are ignored in the find()
> by specifying the key attr as well).

But if there is a row with name == 'Random Girl Band' then it will
find it.  To prove that I attach a patch for the  t/61findnot.t test.

-- 
Zbigniew Lukasiak
http://brudnopis.blogspot.com/
Index: t/61findnot.t
===================================================================
--- t/61findnot.t	(revision 3934)
+++ t/61findnot.t	(working copy)
@@ -7,7 +7,7 @@
 
 my $schema = DBICTest->init_schema();
 
-plan tests => 17;
+plan tests => 18;
 
 my $art = $schema->resultset("Artist")->find(4);
 ok(!defined($art), 'Find on primary id: artist not found');
@@ -44,3 +44,9 @@
 @cd = $cd->single;
 cmp_ok(@cd, '==', 1, 'Return something even in array context');
 ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
+
+$schema->resultset("Artist")->find_or_create({name => 'Random Girl Band'});
+$art = $schema->resultset("Artist")->find({name => 'Random Girl Band'}, {key => 'primary'});
+ok(!defined($art), 'Find on primary key with no key provided: artist not found');
+
+
_______________________________________________
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]

Reply via email to