user
object is saved to the database. You won't know exactly where this method was called from. It could have been the user doing it themselves on the website, or it could have been done from your internal administration area. Generally speaking, you don't need to know this either.result
variable will contain false
because we just fetched the object from the database and did not make any changes to it at all.true
because what is stored in post.title
differs from what is stored in the title
column for this record in the posts
table (well, unless the title was "A New Post Title" even before the change, in which case the result would still be false
).true
if any of them have changed. If you want to see if a specific property has changed, you can pass in property="title"
to it or use the dynamic method XXXHasChanged(). Replace XXX
with the name of the property. In our case, the method would then be named titleHasChanged()
.result
will once again contain false
. When you save a changed (a.k.a. "dirty") object, it clears out its changed state tracking and is considered unchanged again.true
. The reason for this seemingly unexpected behavior is that change is always viewed from the database's perspective. The hasChanged() method will return true
in this case because it is different from what is stored in the database (i.e. it doesn't exist at all in the database yet).