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

No update list for collection classes #260

Closed IlkhamGaysin closed 7 years ago

IlkhamGaysin commented 7 years ago

I see that we can block auto-updating positions in a list only for class to whom call the method acts_as_list_no_update But what if I need to disable for parent or child classes inside a block for example:

class TodoList < ActiveRecord::Base
  has_many :todo_items, -> { order(position: :asc) }
end

class TodoItem < ActiveRecord::Base
  belongs_to :todo_list
  has_many :todo_attachments, -> { order(position: :asc) }

  acts_as_list scope: :todo_list
end

class TodoAttachment < ActiveRecord::Base
  belongs_to :todo_list
  acts_as_list scope: :todo_item
end

TodoItem.acts_as_list_no_update([TodoAttachment]) do
  TodoItem.find(10).update(position: 2)
  TodoAttachment.find(10).update(position: 1)
  TodoAttachment.find(11).update(position: 2)
end

These changes under allow to pass additional classes as an argument and don't update positions for records of the passed classes inside of the block where there might be interactions with them.

Thanks!

IlkhamGaysin commented 7 years ago

Please review guys @swanandp @brendon 🍻

IlkhamGaysin commented 7 years ago

@brendon I've updated the PR please review 🍺

brendon commented 7 years ago

Thanks @IlkhamGaysin, great work! I've merged that for you now :)

IlkhamGaysin commented 7 years ago

@brendon awyeah, thanks :beers: