Hello,
All of a sudden I have a problem with a simple CActiveRecord class used to manage a SQLite 3 table. One DATETIME field has a default value set at database (SQLite) level to ‘current_timestamp’.
Let’s call this field “created_on”.
If I do a simple query “insert into table company (name) values (‘foo’)” I get a record with name=foo and created_on=2021-02-14 20:20:30 which is super fine.
Now in Yii 1.1, when I create a new model I can see that the created_on property has the value ‘current_timestamp’ (a string!!).
Then CActiveRecord saving mechanism is passing this value along to the generated sql statement and I end up with a record in database with created_on=current_timestamp, which is wrong.
It does not seem I can remove created _on from the list of attributes to save.
I have tried to mark this created_on field as ‘unsafe’ in the rules() method so that Yii does not put it in the sql query: No way.
What is possible is to call save with a list of specific attributes you want to appear in the query, but I don’t want to specify the attributes to save, I want to specify those that must not be taken into account.
I was wondering if someone had any idea ?
Thanks in advance.
Note an ugly workaround I have found (Yii patch) is to prevent ‘current_timestamp’ function call to be stored as default value in CActiveRecordMetaData::__construct() with a test to hard coded value ‘current_timestamp’ :
if( !$column->isPrimaryKey
&& (null !== $column->defaultValue)
&& ('current_timestamp' != strtolower( $column->defaultValue ))
)
{
$this->attributeDefaults[$name]=$column->defaultValue;
}