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

Wrong documentation (or implementation) of has_many clear #20170

Closed
pcrwebdesign opened this issue May 15, 2015 · 0 comments · Fixed by #20421
Closed

Wrong documentation (or implementation) of has_many clear #20170

pcrwebdesign opened this issue May 15, 2015 · 0 comments · Fixed by #20421
Labels

Comments

@pcrwebdesign
Copy link

the documentation for Rails 4.1.7 specifies that the method clear:

Removes every object from the collection. This destroys the associated objects if they are associated with dependent: :destroy

However, given that ActiveRecord::Associations::CollectionProxy#clear simply delegates to delete_all and with the change to the implementation of delete_all this is no longer tru:

Removes all records from the association without calling callbacks on the associated records. It honors the :dependent option. However if the :dependent value is :destroy then in that case the :delete_all deletion strategy for the association is applied.

This may be an error in the documentation that needs to be updated, or an undesired effect of the new implementation of delete_all. I personally think that clear should keep honoring the dependent :destroy flag, for backwards compatibility among other reasons.

@pcrwebdesign pcrwebdesign changed the title Wrong documentation of has_many clear Wrong documentation (or implementation) of has_many clear May 15, 2015
@senny senny added the docs label May 18, 2015
repinel added a commit to repinel/rails that referenced this issue Jun 3, 2015
Improve the guide about `has_many` `collection.clear` to indicate
the behavior for each dependent strategy according to
`collection.delete_all`.

Based on rails#17179, I changed the `collection.delete` docs to also
clarify the default strategy for each `hm` and `hm:t` associations.

Fixes rails#20170.
repinel added a commit to repinel/rails that referenced this issue Jun 3, 2015
Improve the guide about `has_many` `collection.clear` to indicate
the behavior for each dependent strategy according to
`collection.delete_all`.

Based on rails#17179, I changed the `collection.delete` docs to also
clarify the default strategy for each `hm` and `hm:t` associations.

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

Successfully merging a pull request may close this issue.

2 participants