8 my $schema = DBICTest->init_schema();
12 # Check that you can leave off the alias
14 my $artist = $schema->resultset('Artist')->find(1);
16 my $existing_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
20 ok(! $existing_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
21 is($existing_cd->title, 'Ted', 'find_or_create on prefetched has_many with same column names: name matches existing entry');
23 my $new_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
24 title => 'Something Else',
27 ok(! $new_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
28 is($new_cd->title, 'Something Else', 'find_or_create on prefetched has_many with same column names: title matches');
31 # Check that you can specify the alias
33 my $artist = $schema->resultset('Artist')->find(1);
35 my $existing_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
36 'me.title' => 'Something Else',
39 ok(! $existing_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
40 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');
42 my $new_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
43 'me.title' => 'Some New Guy',
46 ok(! $new_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
47 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');
50 # Don't pass column names with related alias to new_result
52 my $cd_rs = $schema->resultset('CD')->search({ 'artist.name' => 'Caterwauler McCrae' }, { join => 'artist' });
54 my $cd = $cd_rs->find_or_new({ title => 'Huh?', year => 2006 });
55 ok(! $cd->in_storage, 'new CD not in storage yet');
56 is($cd->title, 'Huh?', 'new CD title is correct');
57 is($cd->year, 2006, 'new CD year is correct');