📅  最后修改于: 2023-12-03 15:19:41.643000             🧑  作者: Mango
In the Rails ActiveRecord framework, saved_change_to
is a method that allows you to determine if an attribute has been changed and saved to the database.
object.saved_change_to_attribute?
true
will be returned.false
will be returned.@user = User.first
@user.name = "John Doe"
@user.saved_change_to_name? #=> true
In this example, the @user.name
attribute has been changed and saved to the database. Therefore, true
is returned from saved_change_to_name?
.
@user = User.first
@user.name = "John Doe"
@user.saved_change_to_name? #=> true
@user.save
@user.saved_change_to_name? #=> false
In this example, the @user.name
attribute has been changed and saved to the database. Therefore, true
is returned from saved_change_to_name?
.
After saving the @user
object, the saved_change_to_name?
method returns false
because the attribute has been saved to the database.