内核更新

This commit is contained in:
2016-08-16 16:14:36 +08:00
parent ebde0fc13e
commit 81a25be484
25 changed files with 340 additions and 129 deletions

View File

@@ -45,6 +45,8 @@ class Relation
protected $joinType;
// 关联模型查询对象
protected $query;
// 关联查询条件
protected $where;
/**
* 架构函数
@@ -93,7 +95,7 @@ class Relation
$result = $relation->where($localKey, $this->parent->$foreignKey)->find();
break;
case self::HAS_MANY:
$result = $relation->where($foreignKey, $this->parent->$localKey)->select();
$result = $relation->select();
break;
case self::HAS_MANY_THROUGH:
$result = $relation->select();
@@ -170,7 +172,8 @@ class Relation
}
if (!empty($range)) {
$data = $this->eagerlyOneToMany($model, [
$this->where[$foreignKey] = ['in', $range];
$data = $this->eagerlyOneToMany($model, [
$foreignKey => [
'in',
$range,
@@ -659,6 +662,14 @@ class Relation
{
if ($this->query) {
switch ($this->type) {
case self::HAS_MANY:
if (isset($this->where)) {
$this->query->where($this->where);
} elseif (isset($this->parent->{$this->localKey})) {
// 关联查询带入关联条件
$this->query->where($this->foreignKey, $this->parent->{$this->localKey});
}
break;
case self::HAS_MANY_THROUGH:
$through = $this->middle;
$model = $this->model;