-
-
Notifications
You must be signed in to change notification settings - Fork 357
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
No update list for collection classes #260
No update list for collection classes #260
Conversation
456277b
to
fe848c1
Compare
* master: Refactor column definer module (brendon#258) Fix deprecation introduced in ActiveRecord 5.1. Add rails 5.1.0.beta1 and ruby 2.4 to test matrix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @IlkhamGaysin :) Thanks for this useful enhancement. I just had a few tweaks for you to make. Let me know if you have any questions :)
README.md
Outdated
the default value from the database. It is your responsibility to correctly manage `positions` values. | ||
the default value from the database. It is your responsibility to correctly manage `positions` values. | ||
|
||
Also you can pass an argument as array of extracted calsses to disable from database updates. It might be any ActiveRecord class that is able to acts as list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should read:
You can also pass an array of classes as an argument to disable database updates on just those classes. It can be any ActiveRecord class that has acts_as_list
enabled.
end | ||
|
||
TodoItem.acts_as_list_no_update([TodoAttachment]) do | ||
TodoItem.find(10).update(position: 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps your example could show an update to TodoList
also, with a comment next to it stating that callbacks will be called on that object.
# TodoList.first.update(position: 2) | ||
# end | ||
# | ||
# Also you can pass an argument as array of extracted calsses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-use the wording from the updated README
.
# end | ||
# | ||
# TodoItem.acts_as_list_no_update([TodoAttachment]) do | ||
# TodoItem.find(10).update(position: 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the example here also as per the README
.
# TodoAttachment.find(11).update(position: 2) | ||
# end | ||
|
||
def acts_as_list_no_update(extra_klasses = [], &block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since extra_klasses
isn't a reserved word I think it should be extra_classes
. Would you agree @swanandp?
test/test_list.rb
Outdated
assert_equal @sub_mixin_1.pos, 2 | ||
assert_equal @sub_mixin_2.pos, 2 | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need a test here that tests that callbacks are still performed on a non-specified acts_as_list
class when called within the block (as per the README
example update.)
e6a78f3
to
f6cd28a
Compare
@brendon I've updated the PR please review 🍺 |
Thanks @IlkhamGaysin, great work! I've merged that for you now :) |
@brendon awyeah, thanks 🍻 |
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:
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!