On Tuesday, November 6, 2012 8:07:55 PM UTC-8, Robert Sosinski wrote: > Hi, > > 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? > > > Sequel refreshes the model when creating, but not when updating. There 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. Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/sequel-talk/-/ATJ_9zJoK8YJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
