Skip to content
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

adds ActiveRecord >= 5.0.0.beta1 support for tree roots; fixes #195 #204

Merged
merged 1 commit into from
Jul 17, 2016

Conversation

jayfredlund
Copy link
Contributor

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 the optional 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.

…ee#195

AR 5 now defaults a `belongs_to` relation to be required.  This does
not work in a tree where the root will not have a `belongs_to :parent` relationship.
 To manage this change, 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,
 so I've added a method that checks the version and strips the `optional` key if necessary.

This will maintain backwards compatibility with AR 4 without changing any
functionality.
@jayfredlund jayfredlund changed the title adds ActiveRecord 5.0.0.beta1 support for tree roots; fixes #195 adds ActiveRecord >= 5.0.0.beta1 support for tree roots; fixes #195 Feb 29, 2016
@seuros seuros merged commit efb2660 into ClosureTree:master Jul 17, 2016
@seuros
Copy link
Member

seuros commented Jul 17, 2016

Awesome work @jayfredlund

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants