|
@@ -3,6 +3,7 @@ namespace Qii\Driver\Entity;
|
|
|
|
|
|
|
|
|
|
|
|
+use Qii\Driver\Model;
|
|
|
use Qii\Driver\Response;
|
|
|
|
|
|
class Base {
|
|
@@ -18,6 +19,11 @@ class Base {
|
|
|
* @var array $config
|
|
|
*/
|
|
|
public static $config;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var Model $db
|
|
|
+ */
|
|
|
+ public static $db = null;
|
|
|
/**
|
|
|
* 主键
|
|
|
* @var mix $privateKeys null
|
|
@@ -499,10 +505,26 @@ class Base {
|
|
|
* @return \Qii\Driver\Base
|
|
|
*/
|
|
|
public function db() {
|
|
|
+ if(self::$db !== null && self::$db instanceof Model) {
|
|
|
+ return self::$db;
|
|
|
+ }
|
|
|
return _loadClass('\Qii\Driver\Model');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * DB 必须是Model类型
|
|
|
+ *
|
|
|
+ * @param $db
|
|
|
+ * @return void
|
|
|
+ * @throws \Exception
|
|
|
+ */
|
|
|
+ final public function setDB($db) {
|
|
|
+ if(!($db instanceof \Qii\Driver\Model)) {
|
|
|
+ throw new \Exception('DB is illegal');
|
|
|
+ }
|
|
|
+ self::$db = $db;
|
|
|
+ }
|
|
|
+ /**
|
|
|
* 返回 entity 信息
|
|
|
* @return mixed
|
|
|
*/
|
|
@@ -1000,7 +1022,7 @@ class Base {
|
|
|
* @return false|Response
|
|
|
*/
|
|
|
public function remove() {
|
|
|
- if(!$this->properties()) {
|
|
|
+ if(!$this->properties() && empty($this->getWhereHooker())) {
|
|
|
return Response::Fail(static::class .'::'. __FUNCTION__,
|
|
|
[
|
|
|
'_result' => ['code' => Response::FAIL_FOR_VALIDATE, 'msg' => '未指定删除目标', 'body' => []],
|
|
@@ -1067,7 +1089,6 @@ class Base {
|
|
|
'diffExclude' => $diffExclude
|
|
|
]
|
|
|
);*/
|
|
|
-
|
|
|
if(count($diffWhere) > 0 || count($diffOr) > 0) {
|
|
|
$unique = $this->db()->limit(1)->where($diffWhere)->orTerms($diffOr)->exclude($exclude)->selectRow($this->prepareTable());
|
|
|
if($unique) {
|
|
@@ -1686,6 +1707,10 @@ class Base {
|
|
|
* @return array
|
|
|
*/
|
|
|
protected function excludeCondition() {
|
|
|
+ $exclude = $this->exclude();
|
|
|
+ if(!$exclude) {
|
|
|
+ $exclude = $this->primaryKey();
|
|
|
+ }
|
|
|
if(is_array($this->exclude())) {
|
|
|
$exclude = $this->exclude();
|
|
|
}else{
|