adds ActiveRecord >= 5.0.0.beta1 support for tree roots; fixes #195 #204
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ActiveRecord 5 now defaults a
belongs_to
relation to be required, which does not work for a tree structure where the root will not have a:parent
.To manage this change in default behavior, AR 5 adds an
optional: true
key, which I have added here. However, this key is not allowed in versions prior to AR 5 and will raise an exception if provided, so its inclusion requires a conditional check to maintain backwards compatibility.Per earlier comments in #196, I've added a method to the
support.rb
file that checks the version and strips theoptional
key if necessary. I've tried to be consistent with the naming of the support method, but am happy to make changes if we'd rather do something different. (Not sure if the name is acceptable, or if you like the use of a ternary operator.)This will maintain backwards compatibility with AR 4 without changing any functionality.