Sequel refreshes the model when creating, but not when updating. There
On Tuesday, November 6, 2012 8:07:55 PM UTC-8, Robert Sosinski wrote:
> I am using Sequel with Postgres. I notice on inserting new records while
> using the `save` method, Sequel::Model uses returning *. However, it does
> not use returning * on update. Is there a way to make it the default on
> updating models too?
isn't a simple way for it to using returning * on updates, but if you need
to refresh after updates, you can call refresh in an after_update hook.
The only real reason to do that is if you have an update trigger or
something else that changes the values stored in the database, and you want
those new values reflected in the model object.
The main reason for this design is that model refreshing is usually
necessary on creation to get values that weren't set in the INSERT call,
while it is only useful during updates in rare cases.
Note that it should be fairly easy to write a plugin that uses RETURNING *
when updating and sets the retrieved values in the model object, if you
don't want the performance hit of another query to refresh.