何回も調べてしまう attribute? の定義箇所

ここを見ると query methods と書かれているので、 https://github.com/rails/rails/blob/master/activerecord/lib/active_record/base.rb

  # == Attribute query methods
  #
  # In addition to the basic accessors, query methods are also automatically available on the Active Record object.
  # Query methods allow you to test whether an attribute value is present.
  # Additionally, when dealing with numeric values, a query method will return false if the value is zero.
  #
  # For example, an Active Record User with the <tt>name</tt> attribute has a <tt>name?</tt> method that you can call
  # to determine whether the user has a name:
  #
  #   user = User.new(name: "David")
  #   user.name? # => true
  #
  #   anonymous = User.new(name: "")
  #   anonymous.name? # => false

ここを見に行くとそれがある https://github.com/rails/rails/blob/master/activerecord/lib/active_record/attribute_methods/query.rb

Rails の save, destroy は自動的に transaction でラップされる

save and destroy are automatically wrapped in a transaction

Both save and destroy come wrapped in a transaction that ensures that whatever you do in validations or callbacks will happen under its protected cover. So you can use validations to check for values that the transaction depends on or you can raise exceptions in the callbacks to rollback, including after_* callbacks.

As a consequence changes to the database are not seen outside your connection until the operation is complete. For example, if you try to update the index of a search engine in after_save the indexer won't see the updated record. The after_commit callback is the only one that is triggered once the update is committed. See below.

ref: ActiveRecord::Transactions::ClassMethods

11/20 気になった記事

11/16 気になった記事

11/13 気になった記事