Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How is touch updated in activerecord base.touch?


Asked by Briar Roth on Nov 28, 2021 FAQ



This new ActiveRecord::Base.touch method updates the User#things_updated_at attribute every time a new Thing is created, updated or removed. It also updates the parent's updated_at field, just like belongs_to :user, touch: true configuration.
Consequently,
Callbacks are hooks into the life cycle of an Active Record object that allow you to trigger logic before or after an alteration of the object state.
Accordingly, Deletes the record in the database and freezes this instance to reflect that no changes should be made (since they can't be persisted). There's a series of callbacks associated with destroy!. If the before_destroy callback throws :abort the action is cancelled and destroy! raises ActiveRecord::RecordNotDestroyed.
Likewise,
By default, save! always runs validations. If any of them fail ActiveRecord::RecordInvalid gets raised, and the record won't be saved. However, if you supply validate: false, validations are bypassed altogether. See ActiveRecord::Validations for more information.
In addition,
Additionally, an after_touch callback is triggered whenever an object is touched. Lastly an after_find and after_initialize callback is triggered for each object that is found and instantiated by a finder, with after_initialize being triggered after new objects are instantiated as well.