1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
10 my $schema = DBICTest->init_schema();
14 # Check that you can leave off the alias
16 my $artist = $schema->resultset('Artist')->find(1);
18 my $existing_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
22 ok(! $existing_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
23 is($existing_cd->title, 'Ted', 'find_or_create on prefetched has_many with same column names: name matches existing entry');
25 my $new_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
26 title => 'Something Else',
29 ok(! $new_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
30 is($new_cd->title, 'Something Else', 'find_or_create on prefetched has_many with same column names: title matches');
33 # Check that you can specify the alias
35 my $artist = $schema->resultset('Artist')->find(1);
37 my $existing_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
38 'me.title' => 'Something Else',
41 ok(! $existing_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
42 is($existing_cd->title, 'Something Else', 'find_or_create on prefetched has_many with same column names: can be disambiguated with "me." for existing entry');
44 my $new_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
45 'me.title' => 'Some New Guy',
48 ok(! $new_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
49 is($new_cd->title, 'Some New Guy', 'find_or_create on prefetched has_many with same column names: can be disambiguated with "me." for new entry');
52 # Don't pass column names with related alias to new_result
54 my $cd_rs = $schema->resultset('CD')->search({ 'artist.name' => 'Caterwauler McCrae' }, { join => 'artist' });
56 my $cd = $cd_rs->find_or_new({ title => 'Huh?', year => 2006 });
57 is($cd->in_storage, 0, 'new CD not in storage yet');
58 is($cd->title, 'Huh?', 'new CD title is correct');
59 is($cd->year, 2006, 'new CD year is correct');