Rails: How Does. Clear Differ From. Destroy?

Does .clear invoke callbacks? Does it just empty the array of objects but not delete them?

1 Answer

I assume you're talking about calling clear or destroy on an ActiveRecord association (if so, please provide those details in your question). In that case, clear does not run callbacks, and destroy does. See ActiveRecord::Associations::ClassMethods.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest