No, I don’t use afterSave. After quite some hours of work, I could reproduce the problem with the following minimal example.
Test1::model()->deleteAll();
Test2::model()->deleteAll();
$a = new Test1;
$a->text = 'orig';
$a->save();
# $a = Test1::model()->findByPk($a->id); # temporary workaround
$bb = new Test2;
$bb->save();
$a->text = 'changed';
$a->save();
die('Now look in the database. Instead of "changed", I see "orig" there.');
DB definition and models[spoiler]
CREATE TABLE IF NOT EXISTS `Test1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`text` text NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE IF NOT EXISTS `Test2` (
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
);
class Test1 extends CActiveRecord {
public static function model($className=__CLASS__) {
return parent::model($className);
}
}
class Test2 extends CActiveRecord {
public static function model($className=__CLASS__) {
return parent::model($className);
}
i have the same problem. Have anyone solved it in a better way? If i load a model out of my database (innodb) then the flag isNewRecord is set to true but the data from the database is inside the model class. If i try to save the database returns that the pk is already in use because the ar model object does a insert instead of an update because the flag is wrong.
I can set the flag manually but by whole application has the same problem and this isn’t a sufficient solution.