Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require a scope to be present before re-ordering #389

Closed
tomchapin opened this issue Jan 20, 2021 · 3 comments
Closed

Require a scope to be present before re-ordering #389

tomchapin opened this issue Jan 20, 2021 · 3 comments

Comments

@tomchapin
Copy link

I'm running into an issue where acts_as_list is attempting to re-order every single item that isn't associated with the scope.

For example, we have a bunch of images that are associated with products, and acts_as_list is scoped to product_id, like so:

acts_as_list scope: :product, column: :order_index

The problem is that we also have numerous images in the system which are NOT associated with any product. This means that every time one of those disassociated images is touched, acts_as_list attempts to re-order hundreds of thousands of images in the system that have a null product id.

Is there a way to make act_as_list skip the re-ordering process if the required scope isn't actually defined?

We came up with this really hacky way of doing it, but I'm not happy with it. Surely there's a better way?

acts_as_list scope: 'images.product_id = #{(product_id.present? ? product_id : false)}', column: :order_index
@brendon
Copy link
Owner

brendon commented Jan 20, 2021

Hi @tomchapin, thanks for reaching out :)

I think currently NULL is considered just another value for the scope (in addition to integer id's).

I'd imagine if we want to make acts_as_list support ignoring NULL scope id's, it'd have to be written as a new feature.

I currently don't have time to do this myself, but if you feel comfortable creating a PR with a well tested feature addition then I'd be more than happy to review it and get it into the gem :)

I'm thinking that it'd be an option passed to acts_as_list that is off by default so it doesn't interfere with existing implementations that might rely on NULL being sortable too.

Hope that helps! :)

@brendon
Copy link
Owner

brendon commented Jan 21, 2021

Related: #92

@brendon
Copy link
Owner

brendon commented Jun 4, 2024

Closing due to lack of followup. @tomchapin, if you want to explore this further let me know. I'd say check out my new positioning gem: https://github.com/brendon/positioning but even in that gem we assume an item is always in the list. You can pretend it isn't by ignoring say a boolean scope when it's false but we'll still maintain positions within that false scope.

@brendon brendon closed this as completed Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants