1、内核修复

2、用户模块完善和bug修复
This commit is contained in:
2016-07-15 11:59:56 +08:00
parent 9ad5d5fd9c
commit ad1f4c029e
14 changed files with 122 additions and 174 deletions

View File

@@ -43,6 +43,8 @@ class Relation
protected $alias;
// 当前关联的JOIN类型
protected $joinType;
// 关联模型查询对象
protected $query;
/**
* 架构函数
@@ -409,7 +411,7 @@ class Relation
$this->localKey = $localKey;
$this->alias = $alias;
$this->joinType = $joinType;
$this->query = (new $model)->db();
// 返回关联的模型对象
return $this;
}
@@ -433,7 +435,7 @@ class Relation
$this->localKey = $otherKey;
$this->alias = $alias;
$this->joinType = $joinType;
$this->query = (new $model)->db();
// 返回关联的模型对象
return $this;
}
@@ -455,7 +457,7 @@ class Relation
$this->foreignKey = $foreignKey;
$this->localKey = $localKey;
$this->alias = $alias;
$this->query = (new $model)->db();
// 返回关联的模型对象
return $this;
}
@@ -481,7 +483,7 @@ class Relation
$this->throughKey = $throughKey;
$this->localKey = $localKey;
$this->alias = $alias;
$this->query = (new $model)->db();
// 返回关联的模型对象
return $this;
}
@@ -505,7 +507,7 @@ class Relation
$this->localKey = $localKey;
$this->middle = $table;
$this->alias = $alias;
$this->query = (new $model)->db();
// 返回关联的模型对象
return $this;
}
@@ -653,14 +655,12 @@ class Relation
public function __call($method, $args)
{
if ($this->model) {
$model = new $this->model;
$db = $model->db();
if ($this->query) {
switch ($this->type) {
case self::HAS_MANY:
if (isset($this->parent->{$this->localKey})) {
// 关联查询带入关联条件
$db->where($this->foreignKey, $this->parent->{$this->localKey});
$this->query->where($this->foreignKey, $this->parent->{$this->localKey});
}
break;
case self::HAS_MANY_THROUGH:
@@ -671,13 +671,18 @@ class Relation
$pk = (new $this->model)->getPk();
$throughKey = $this->throughKey;
$modelTable = $this->parent->getTable();
$result = $db->field($alias . '.*')->alias($alias)
$result = $this->query->field($alias . '.*')->alias($alias)
->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey)
->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey)
->where($throughTable . '.' . $this->foreignKey, $this->parent->{$this->localKey});
break;
}
return call_user_func_array([$db, $method], $args);
$result = call_user_func_array([$this->query, $method], $args);
if ($result instanceof \think\db\Query) {
return $this;
} else {
return $result;
}
} else {
throw new Exception('method not exists:' . __CLASS__ . '->' . $method);
}