On Monday, September 30, 2013 12:49:42 PM UTC-7, Marcel van Pinxteren wrote:
>
> I only just started to look into Sequel, to see if it is a better fit for
> us than ActiveRecord.
> My first impression is good, but I am running into an issue.
> We use MS SQL via TinyTds. All of our tables have a TimeStamp column, that
> is of the type timestamp, or ROWVERSION in recent versions of SQL server.
> NB: this is NOT a datetime field. It contains 8 bytes; with every update
> of a record, the value of this field increases. This helps to implement
> optimistic concurrency.
>
> A timestamp field should be treated as read-only, but the piece of code of
> Sequel that creates UPDATE statements, tries to update this field. Of
> course, this fails miserably.
> The best solution would be for Sequel to exclude this type of fields from
> UPDATE and INSERT statements. A workaround could be to specify the columns
> in the .save instruction, excluding the timestamp field. Not very nice.
>
Well, if you use Model#save_changes/#update instead of #save, then the
column shouldn't be included in the UPDATE statement. You can just remove
it before updating if you want to use #save:
def before_update
values.delete(:column_name)
super
end
The only issue there is then the value is not available after updating.
You can fix that by deleting it before the update and setting it back after
update, which is left as an exercise to the reader.
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.