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