改名
This commit is contained in:
@@ -12,6 +12,8 @@ namespace Database;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use Database\Base\BaseActiveRecord;
|
use Database\Base\BaseActiveRecord;
|
||||||
use Snowflake\Core\ArrayAccess;
|
use Snowflake\Core\ArrayAccess;
|
||||||
|
use Snowflake\Error\Logger;
|
||||||
|
use Snowflake\Snowflake;
|
||||||
|
|
||||||
defined('SAVE_FAIL') or define('SAVE_FAIL', 3227);
|
defined('SAVE_FAIL') or define('SAVE_FAIL', 3227);
|
||||||
|
|
||||||
@@ -101,6 +103,28 @@ class ActiveRecord extends BaseActiveRecord
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $attributes
|
||||||
|
* @param $condition
|
||||||
|
* @return bool|ActiveRecord|mixed
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static function findOrCreate(array $condition, array $attributes = [])
|
||||||
|
{
|
||||||
|
$select = static::find()->where($condition)->first();
|
||||||
|
if (!empty($select)) {
|
||||||
|
return $select;
|
||||||
|
}
|
||||||
|
if (empty($attributes)) {
|
||||||
|
$message = 'Create a new model, but the data cannot be empty.';
|
||||||
|
return Snowflake::app()->logger->addError($message, 'mysql');
|
||||||
|
}
|
||||||
|
$select = new static();
|
||||||
|
$select->attributes = $attributes;
|
||||||
|
return $select->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $action
|
* @param $action
|
||||||
* @param $columns
|
* @param $columns
|
||||||
|
|||||||
Reference in New Issue
Block a user