10 my $schema = DBICTest->init_schema();
12 my $art = $schema->resultset("Artist")->find(4);
13 ok(!defined($art), 'Find on primary id: artist not found');
14 my @cd = $schema->resultset("CD")->find(6);
15 cmp_ok(@cd, '==', 1, 'Return something even in array context');
16 ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
18 $art = $schema->resultset("Artist")->find({artistid => '4'});
19 ok(!defined($art), 'Find on unique constraint: artist not found');
20 @cd = $schema->resultset("CD")->find({artist => '2', title => 'Lada-Di Lada-Da'});
21 cmp_ok(@cd, '==', 1, 'Return something even in array context');
22 ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
24 $art = $schema->resultset("Artist")->search({name => 'The Jesus And Mary Chain'});
25 isa_ok($art, 'DBIx::Class::ResultSet', 'get a DBIx::Class::ResultSet object');
26 my $next = $art->next;
27 ok(!defined($next), 'Nothing next in ResultSet');
28 my $cd = $schema->resultset("CD")->search({title => 'Rubbersoul'});
30 cmp_ok(@cd, '==', 1, 'Return something even in array context');
31 ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
33 $art = $schema->resultset("Artist")->single({name => 'Bikini Bottom Boys'});
34 ok(!defined($art), 'Find on primary id: artist not found');
35 @cd = $schema->resultset("CD")->single({title => 'The Singles 1962-2006'});
36 cmp_ok(@cd, '==', 1, 'Return something even in array context');
37 ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
39 $art = $schema->resultset("Artist")->search({name => 'Random Girl Band'});
40 isa_ok($art, 'DBIx::Class::ResultSet', 'get a DBIx::Class::ResultSet object');
42 ok(!defined($next), 'Nothing next in ResultSet');
43 $cd = $schema->resultset("CD")->search({title => 'Call of the West'});
45 cmp_ok(@cd, '==', 1, 'Return something even in array context');
46 ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
48 $cd = $schema->resultset("CD")->first;
49 my $artist_rs = $schema->resultset("Artist")->search({ artistid => $cd->artist->artistid });
50 for my $key ('', 'primary') {
51 my $art = $artist_rs->find({ name => 'some other name' }, { $key ? (key => $key) : () });
52 is($art->artistid, $cd->get_column('artist'), "Artist found through @{[ $key ? 'explicit' : 'implicit' ]} key locked in the resultset");
55 # collapsing and non-collapsing are separate codepaths, thus the separate tests
58 $artist_rs = $schema->resultset("Artist");
62 } qr/\QQuery returned more than one row. SQL that returns multiple rows is DEPRECATED for ->find and ->single/
63 => "Non-unique find generated a cursor inexhaustion warning";
66 $artist_rs->find({}, { key => 'primary' })
67 } qr/Unable to satisfy requested constraint 'primary'/;
70 local $ENV{DBIC_NULLABLE_KEY_NOWARN};
73 $artist_rs->find({ artistid => undef }, { key => 'primary' })
76 qr/undef values supplied for requested unique constraint.+almost certainly not what you wanted/,
78 'One warning on NULL conditions for constraint'
83 $artist_rs = $schema->resultset("Artist")->search({}, { prefetch => 'cds' });
87 } qr/\QDBIx::Class::ResultSet::find(): Query returned more than one row/, "Non-unique find generated a cursor inexhaustion warning";
90 $artist_rs->find({}, { key => 'primary' })
91 } qr/Unable to satisfy requested constraint 'primary'/;