brendon / acts_as_list

An ActiveRecord plugin for managing lists.
http://brendon.github.io/acts_as_list/
MIT License
2.04k stars 355 forks source link

Unscoping breaks STI subclasses, but is soon to be fixed in Rails #291

Closed andrewhao closed 6 years ago

andrewhao commented 6 years ago

Upstream Rails (5.1.x) has a just-fixed issue where calling unscoped breaks any models that use STI (https://github.com/rails/rails/pull/29199) due to the type condition in the where clause being removed.

This isn't really an issue, but I just wanted to flag this in case someone else stumbles across this.

Temporary workaround is to add a type: 'Subclass' field in the scope definition:

class SpecialThing < BaseThing
  acts_as_list scope: [type: 'SpecialThing']
end
brendon commented 6 years ago

That's a tricky one hey? We could just unscope the fields we care about? If you wanted to take a look and see if there's anything we can do from our end, please do :) My timetable is full for the next 4 weeks or so unfortunately so I can't look very deeply at this.

bsylvain commented 6 years ago

I have the same problem. If you already used a scope here is the workaround adapted : acts_as_list scope: :some_container you can do (same context as first example) : acts_as_list scope: [:some_container, type: 'SpecialThing']

brendon commented 6 years ago

@andrewhao, did you want to progress this issue?

andrewhao commented 6 years ago

Hi @brendon - given I've found a workaround, I don't feel strongly about this and would defer to you on your timeline. Thanks for your work on this!

brendon commented 6 years ago

Thanks @andrewhao, I think I'll close this as sometimes it's not possible for us to know the fields to unscope (if they're passed in as a string). And since you have a workaround, and since Rails has fixed this, over time it won't be an issue and people can come here for the workaround if needed :)