[Dbix-class] Updating foreign key does not reload related object

Jess Robinson castaway at desert-island.me.uk
Wed Aug 1 08:03:03 GMT 2007



On Wed, 1 Aug 2007, brett gardner wrote:

> I have a row object which has a field "venue_id" which is a foreign key used 
> in a belongs_to relationship "venue".
>
> When I do the following.
>
>    $old_venue = $event->venue;
>    $event->venue_id($new_id);
>    $event->update;
>    $new_venue = $event->venue;
>
> "$new_venue" is not the venue with primary key "$new_id", it is the same row 
> as "$old_venue".
>
> Is this meant to update automatically or is this a feature not yet 
> implemented?
>

Nope, it does that on purpose..

You can update and change a related object at the same time by doing:
$event->update({venue => $new_venue_object});

Jess




More information about the Dbix-class mailing list