fixup to work round an aliasing bug
[dbsrgits/DBIx-Class.git] / t / 79aliasing.t
CommitLineData
ab8481f5 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
8my $schema = DBICTest->init_schema();
9
10plan tests => 8;
11
77211009 12my $artist = $schema->resultset('Artist')->find(1);
ab8481f5 13
14# Check that you can leave off the alias
15{
77211009 16 my $existing_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
17 title => 'Ted',
18 year => 2006,
ab8481f5 19 });
77211009 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');
ab8481f5 22
77211009 23 my $new_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
24 title => 'Something Else',
25 year => 2006,
ab8481f5 26 });
77211009 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');
ab8481f5 29}
30
31# Check that you can specify the alias
32{
77211009 33 my $existing_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
34 'me.title' => 'Something Else',
35 'me.year' => 2006,
ab8481f5 36 });
77211009 37 ok(! $existing_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
38 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');
ab8481f5 39
77211009 40 my $new_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({
41 'me.title' => 'Some New Guy',
42 'me.year' => 2006,
ab8481f5 43 });
77211009 44 ok(! $new_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean');
45 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');
ab8481f5 46}