X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F79aliasing.t;h=00e5e930abf42a5363229b5027b8076662ec32ab;hb=a524980e87f8d0063f051a4f949e0a4a20cd4a8f;hp=6e73f104e515e18838f4040dc0fc575f62ad93c2;hpb=77211009a2ce3dc56574a59053075c9bb545449a;p=dbsrgits%2FDBIx-Class.git diff --git a/t/79aliasing.t b/t/79aliasing.t index 6e73f10..00e5e93 100644 --- a/t/79aliasing.t +++ b/t/79aliasing.t @@ -1,5 +1,5 @@ use strict; -use warnings; +use warnings; use Test::More; use lib qw(t/lib); @@ -7,12 +7,12 @@ use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 8; - -my $artist = $schema->resultset('Artist')->find(1); +plan tests => 11; # Check that you can leave off the alias { + my $artist = $schema->resultset('Artist')->find(1); + my $existing_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({ title => 'Ted', year => 2006, @@ -30,6 +30,8 @@ my $artist = $schema->resultset('Artist')->find(1); # Check that you can specify the alias { + my $artist = $schema->resultset('Artist')->find(1); + my $existing_cd = $artist->search_related('cds', undef, { prefetch => 'tracks' })->find_or_create({ 'me.title' => 'Something Else', 'me.year' => 2006, @@ -44,3 +46,13 @@ my $artist = $schema->resultset('Artist')->find(1); ok(! $new_cd->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean'); 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'); } + +# Don't pass column names with related alias to new_result +{ + my $cd_rs = $schema->resultset('CD')->search({ 'artist.name' => 'Caterwauler McCrae' }, { join => 'artist' }); + + my $cd = $cd_rs->find_or_new({ title => 'Huh?', year => 2006 }); + is($cd->in_storage, 0, 'new CD not in storage yet'); + is($cd->title, 'Huh?', 'new CD title is correct'); + is($cd->year, 2006, 'new CD year is correct'); +}