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

Gavin Carr gavin at openfusion.com.au
Tue May 9 12:31:59 CEST 2006


> > On Sat, Apr 29, 2006 at 05:18:54PM +0100, Matt S Trout wrote:
> >> 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:
> >>>
> >>>   # 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.

Sorry to revisit this, but I'm still having problems. As Matt said, 
changing to using '$cd->artist($mj->artistid)' (instead of set_column)
fixed the problem in my test case.

It didn't fix the problem in my app though. The only difference seems 
to be that in the above the column and relationship name match, so
Main/Cd.pm uses the two-arg form of belongs_to:

  __PACKAGE__->belongs_to('artist' => 'MyDatabase::Main::Artist')

where I tend to make my columns match (both 'artistid') and distinguish 
the relationship, so I use the three-arg form of belongs_to:

  __PACKAGE__->belongs_to('artist' => 'MyDatabase::Main::Artist', 'artistid')

Changing the Example schema to match, my test script (attached) fails 
- the important bit is:

  # Update $cd foreign key 
  $cd->artistid($mj->artistid);
  $cd->update;

  # Check - both these should succeed, but the second fails
  is($cd->artistid, $mj->artistid, 'cd artist col is now $mj id');
  is($cd->artist->artistid, $mj->artistid, 'cd artist rel is now $mj');

failing thus:

  ok 7 - cd artist col is now $mj id
  not ok 8 - cd artist rel is now $mj
  #   Failed test 'cd artist rel is now $mj'
  #   in 01_fkey_update.t at line 28.
  #          got: '2'
  #     expected: '1'
  # Looks like you failed 1 test of 8.

So does this look like a bug, or am I doing something else stupid?

Cheers,
Gavin


-------------- next part --------------
A non-text attachment was scrubbed...
Name: 01_fkey_update.t
Type: application/x-troff
Size: 992 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/dbix-class/attachments/20060509/6051e493/attachment.t 


More information about the Dbix-class mailing list