[Dbix-class] Updating foreign key does not reload related object
Matt S Trout
dbix-class at trout.me.uk
Fri Aug 3 16:42:29 GMT 2007
On Thu, Aug 02, 2007 at 09:00:19AM +1000, brett gardner wrote:
> Matt S Trout wrote:
> >On Wed, Aug 01, 2007 at 01:00:03PM +1000, 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?
> >>
> >
> >$obj->venue($new_venue);
> >
> >will do the right thing. Don't bypass the abstraction if you want to use
> >the abstraction later :)
> >
> >
> (top-posting fixed)
>
> I couldn't find in the documentation that this was possible. Is it also
> now possible to do
>
> my $obj = $schema->resultset('Event')->create({venue=>$existing_venue});
Yep, although in that case I'd likely use $venue->events->create instead
--
Matt S Trout Need help with your Catalyst or DBIx::Class project?
Technical Director Want a managed development or deployment platform?
Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/
More information about the DBIx-Class
mailing list