Closed s4na closed 2 years ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I think we're also running into this. Did you find a workaround @s4na?
@phansch
class Category < ApplicationRecord
acts_as_nested_set
validate :check_parent_id
def check_parent_id
finded_parent = Category.find_by(id: parent_id)
p finded_parent
end
end
When I changed
config.active_record.has_many_inversing
totrue
, which was added in Rails 6.1, the behavior changed.Is this intentional?
Changed behavior
Referencing
#parent
inside #validate when updatingparent_id
will refer to the old parent.Benefits of modification
Validation can be used when the model is saved.
Steps to reproduce
The detailed source code is here.
When the setting is
config.active_record.has_many_inversing = true
-> https://github.com/s4na/issue-awesome_nested_setWhen the setting is
config.active_record.has_many_inversing = false
-> https://github.com/s4na/issue-awesome_nested_set/tree/has_many_inversing-falseconfig
config.active_record.has_many_inversing = true
config.active_record.has_many_inversing = false
Model
Schema
Test
Results
config.active_record.has_many_inversing = true
Referring to the old parent.
config.active_record.has_many_inversing = false
Best regards, s4na