userobject 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.
resultvariable will contain
falsebecause we just fetched the object from the database and did not make any changes to it at all.
truebecause what is stored in
post.titlediffers from what is stored in the
titlecolumn for this record in the
poststable (well, unless the title was "A New Post Title" even before the change, in which case the result would still be
trueif 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
XXXwith the name of the property. In our case, the method would then be named
resultwill 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
truein 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).