On Mon, Oct 19, 2020 at 1:25 PM [email protected] <[email protected]>
wrote:

>
> I have a situation where I want to set values in a few columns of a bunch
> of related rows, and write those changes out.  I most cases, the data will
> remain unchanged, but I don't want to add a ton of extra logic to prevent
> writes.
>
> As an extreme oversimplification, suppose I have an array of rows that
> I've updated a "location" column, and it may be the exact value it already
> has.
>
> For example,
>
>
> *rows.each do |row|*
> *  row.location = # some code to set location*
> *end*
>
> If I do this:
>
> *rows.each { |row| row.save_changes }*
>
> Its still sends an update statement to postgres, even if the location is
> the the same as when it was originally read.
>
> I've used the dirty plugin to solve this by doing this
>
> *rows.each { |row| row.save_changes if row.column_changes.any? }*
>
> and that seems to work, but I am wondering if I'm missing something that's
> built in to Sequel.   We're currently using a 4.x version of Sequel.
>

Sequel does check to see if the value is the same before adding the column
to changed_columns:

  if new? || !vals.include?(column) || v != (c = vals[column]) || v.class
!= c.class
    change_column_value(column, v)
  end

That code hasn't changed since 2012.  Not sure why that isn't handling your
case.  Is the class different?

If you could provide a minimal, self contained example showing the problem
with the current version of Sequel, I may be able to provide more help.

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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/CADGZSSfHd9EF%2BbNMBOVWL2Afgca8-N3P%3DwwcYqHsR%2B7cSom7yQ%40mail.gmail.com.

Reply via email to