Em 13-05-2017 19:06, Jeremy Evans escreveu:
On Friday, May 12, 2017 at 3:33:10 PM UTC-7, Rodrigo Rosenfeld Rosas wrote:

    Hi Jeremy, I called "set_dataset dataset.filter(deleted: false)"
    in my Field class.

    Now, after upgrading Sequel, I get a problem because previously if
    I called instance.update(position: 2) it would generate something
    like "update fields set position=2 where (id=23)" but now it
    generates something like:

    update fields set position=2 where (("deleted" is false) and ("id"
    = 23));

    How can I ignore the default dataset when saving an existing
    instance that would be filtered otherwise?


What version are you upgrading from? I think Sequel's behavior in this area hasn't changed in a long time. Here's some code that shows the same behavior in the current version and in Sequel 3:

DB.create_table(:bs){primary_key :id; TrueClass :deleted; String :name}
class B < Sequel::Model
  set_dataset dataset.filter(:deleted=>false)
end
b = B.create(:deleted=>false, :name=>'a')
b.update(:deleted=>true)
b.update(:name=>'b')

From a modeling perspective, it doesn't really make sense to ignore the dataset's filter. However, Sequel allows changing the instance dataset separately from the model dataset, though there isn't an API for it:

class Field < Sequel::Model
  set_dataset dataset.filter(deleted: false)
  @instance_dataset = instance_dataset.unfiltered
end


Oh, that certainly explains. I had two lines next to a comment explaining why unfiltered was being called in set_dataset due to some autoreloading issues that existed at that time. I mistakenly thought both lines were related to the hack and commented the second line which was giving a deprecation warning. The second line was:

instance_dataset.unfiltered!

It wasn't obvious I should replace it with @instance_dataset = instance_dataset.unfiltered when I noticed that warning and since I didn't know what was its purpose I just decided to comment it out and since this happened with many more changes I didn't realize commenting this line was actually the cause for one of our tests to fail.

Thanks for the insights! :)

Have a great weekend! :)

Rodrigo.

--
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 https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to