问题
Yii 1.1.12: When I select an instance of the User model, I get the default value for certain properties/columns. This happens for columns that I have recently added (manually) to the database:
$user->locale // returns null (= default value)
If I set a new, different default value in the database (via phpMyAdmin), I will receive that new default value.
Other columns of that table do just fine:
$user->email // returns the correct value
I will receive the correct value if I run an SQL query:
SELECT locale FROM tbl_users WHERE tbl_users.id = :userID LIMIT 1
From this I deduce that the database is just fine. The problem must be in the Active Records implementation.
I would expect that Yii's magic methods simply find each database column and add them as a (virtual) property to the model. This appears to be happening, but somehow the database-column default value is interjected.
What am I doing wrong?
Solution: As Sam suggested, removing defaultScope() did the trick. Apparently, a AR-property must be listed in defaultScope() to be recognized. Alternatively, defaultScope() can be removed in its entirety.
回答1:
Have you cleaned up Yii cache after adding deafault values to MySQL?
来源:https://stackoverflow.com/questions/13550296/yii-activerecord-field-only-returns-default-value-for-recently-added-column