This commit is contained in:
2020-11-18 15:05:33 +08:00
parent 22ce82d0f6
commit 2e0493069f
+2 -2
View File
@@ -115,14 +115,14 @@ class ActiveRecord extends BaseActiveRecord
*/
public static function findOrCreate(array $condition, array $attributes = [])
{
$select = self::find()->where($condition)->first();
$select = static::find()->where($condition)->first();
if (!empty($select)) {
return $select;
}
if (empty($attributes)) {
return \logger()->addError(FIND_OR_CREATE_MESSAGE, 'mysql');
}
$select = new self();
$select = new static();
$select->attributes = $attributes;
if (!$select->save()) {
throw new Exception($select->getLastError());