brendon/positioning

Disabling temporarily

mattwigham opened this issue · 7 comments

Hi @brendon, thanks so much for the gem. Is there a way to disable it temporarily to do manual mass updates? Something similar to your acts_as_list_no_update method?

Thanks @mattwigham :) Happy to hear it's been of use.

There currently isn't a way to disable the gem callbacks conditionally. Can you run through the bulk updates you want to do? It could be something we add, but I'm trying to keep the library as slim as possible. Is it the case that you want other callbacks to run and just not ours?

My use case is cloning a parent item and its list of children items. So all children already have explicit positions set, they just need to be maintained exactly.

Thinking about this more, rather than providing a way to shoot yourself in the foot, perhaps it might work better to augment dup (which I assume you're using to copy your model instances) so that it resets the position to nil just like Rails resets the id to nil for similar reasons. What do you think? Then the order would be set based on the order you save your duplicated children. I might implement that in a branch for you to try out to see if it does the trick :)

https://jonleighton.name/2011/initialize_clone-initialize_dup-and-initialize_copy-in-ruby/

https://github.com/rails/rails/blob/57fe7e781ee37a50e54b17df24738ce6c26b22db/activerecord/lib/active_record/core.rb#L516-L543

@brendon works great! Nice simple solution. :)

Nice! I'll merge that into main. I'm currently also trying to make the advisory lock less all-powerful but aren't having as much luck at that.

Released as 0.3.0.