[Dbix-class] Bug (?) with foreign key / relationship updates
Gavin Carr
gavin at openfusion.com.au
Sat Apr 29 07:12:02 CEST 2006
There seems to be a bug in .06002 where an update on a foreign key
does not get picked up by the relationship (belongs_to) attached to
that key. Example, from the DBIx::Class::Manual::Example schema:
my $mj = $schema->resultset('Artist')->search_like({ name => 'Michael%' })->first;
my $em_rs = $schema->resultset('Artist')->search({ name => 'Eminem' });
my $em = $em_rs->first;
my $cd = $em_rs->search_related('cds')->first;
is($mj->name, 'Michael Jackson', '$mj ok');
is($em->name, 'Eminem', '$em ok');
is($cd->get_column('artist'), $em->artistid, 'cd artist col is $em id');
is($cd->artist->artistid, $em->artistid, 'cd artist rel is $em');
# Update $cd foreign key
$cd->set_column('artist', $mj->artistid);
$cd->update;
# Check - both these should succeed, but the second fails
is($cd->get_column('artist'), $mj->artistid, 'cd artist col now is $mj id');
is($cd->artist->artistid, $mj->artistid, 'cd artist rel now is $mj');
Per the comment, the final test fails:
1..8
ok 1 - use MyDatabase::Main;
ok 2 - schema defined
ok 3 - $mj ok
ok 4 - $em ok
ok 5 - cd artist col is $em id
ok 6 - cd artist rel is $em
ok 7 - cd artist col now is $mj id
not ok 8 - cd artist rel now is $mj
# Failed test 'cd artist rel now is $mj'
# in 01_fkey_update.t at line 28.
# got: '2'
# expected: '1'
# Looks like you failed 1 test of 8.
Test attached.
Cheers,
Gavin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 01_fkey_update.t
Type: application/x-troff
Size: 1040 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/dbix-class/attachments/20060429/01f7016b/attachment.t
More information about the Dbix-class
mailing list