published on in josbos

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.

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJoaG5vZWeCcoKOq5iipKNitbDDjJ2mnqtdmLmmrdFmm6Kelpq%2FbrLRqKRmnJWowbO72A%3D%3D