[Dbix-class] Update

Martin Bendix martinbendix at yahoo.co.uk
Fri Aug 5 17:03:46 GMT 2011


Hi,

Using "create" in DBIx::Class::ResultSet, I can specify a hashref of 
related-object column values, and that will cause the appropriate foreign key 
for the `belongs_to` relationship to be looked-up and included in the row:

$row = $event_rs->create({
    event => "My event",
    recur => { freq => "daily" },
});

Is it possible to perform a similar action when updating the row?  For example, 
something like this:

$row->update({
    event => "My updated event",
    recur => { freq => "weekly" },
});

The above fails because the update method is expecting a row object for the 
relation, not a hashref.  At the moment, I am performing a separate "find" to 
locate the matching "recur" row, then using that in the "update" method:

$recur = $recurrence_rs->find({ freq => "weekly" });

$row->update({
    event => "My updated event",
    recur => $recur,
});




Many thanks,

Martin



More information about the DBIx-Class mailing list