[Dbix-class] Bug (?) with foreign key / relationship updates

Matt S Trout dbix-class at trout.me.uk
Sat Apr 29 18:18:54 CEST 2006


Gavin Carr wrote:
> 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;

Err, but you just bypassed the stuff that actually triggers the clear on the 
related object -

$cd->artist($mj);

or

$cd->artist($mj->artistid);

would both work.

-- 
      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Dbix-class mailing list