Hi, I’m new to Yii framework (and I’m implementing it to all new projects with my team), and I have a question which I couldn’t find a solution for neither on forum or on documentation.
I have a table which rows needs to be updated if a field already exists (unique) or be inserted if there’s not.
I was able to make it that way:
$modelTest = ModelTest::model()->find('secondField=:secondField', array(':secondField' => $secondField));
if(!$modelTest) {
$modelTest = ModelTest::model();
$modelTest->isNewRecord = true;
}
$modelTest->loremIpsum = 'dolor sit amet';
$modelTest->save(false); // Saves ignoring the validation, just for test purposes
I think that redeclaration is oddly ugly, so, isn’t there an easier way?