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

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

Reply via email to