Wednesday, January 30, 2008

Refreshing a row from the DB - another note to myself

This is another thing that I keep forgetting - how to refresh a row with values from the database.
So here it is:

$row->discard_changes;

It comes from DBIx::Class::PK (and not from DBIx::Class::Row where I usually start the serach).

Update: The core devs say that the new version of documentation will mention discard_changes in DBIx::Class::Row POD. Thanks.

2 comments:

Anonymous said...

Actually, discard_changes doesn't work at all without the PK - fortunately SERIAL is handled just fine by the last_insert_id stuff in Storage. The point of using discard_changes as a refresh is where there are non-PK columns that you need to reload.

zby said...

Thanks. I've updated the note.