Hey Jeremy,
With Sequel and Postgres, I can do the following:
DB[:people].where(:id => 1).returning('*'.lit).update(:first_name =>
'Alice')
This lets me update the record and get back the row from the database after
triggers. Would it be possible plug the `returning` method into the save
method when using updates? If it is more complicated then that, could you
let me know why.
Really appreciate the help.
On Wednesday, November 7, 2012 1:15:16 AM UTC-5, Jeremy Evans wrote:
>
> 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/-/CAwAtUI10k4J.
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.