mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 23:02:48 +08:00
改进关联模型
This commit is contained in:
@@ -50,7 +50,13 @@ class BelongsTo extends OneToOne
|
|||||||
if ($closure) {
|
if ($closure) {
|
||||||
call_user_func_array($closure, [ & $this->query]);
|
call_user_func_array($closure, [ & $this->query]);
|
||||||
}
|
}
|
||||||
return $this->query->where($this->localKey, $this->parent->$foreignKey)->relation($subRelation)->find();
|
$relationModel = $this->query
|
||||||
|
->where($this->localKey, $this->parent->$foreignKey)
|
||||||
|
->relation($subRelation)
|
||||||
|
->find();
|
||||||
|
$relationModel->setParent(clone $this->parent);
|
||||||
|
|
||||||
|
return $relationModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -47,7 +47,14 @@ class HasMany extends Relation
|
|||||||
if ($closure) {
|
if ($closure) {
|
||||||
call_user_func_array($closure, [ & $this->query]);
|
call_user_func_array($closure, [ & $this->query]);
|
||||||
}
|
}
|
||||||
return $this->relation($subRelation)->select();
|
$list = $this->relation($subRelation)->select();
|
||||||
|
$parent = clone $this->parent;
|
||||||
|
|
||||||
|
foreach ($list as &$model) {
|
||||||
|
$model->setParent($parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ class HasManyThrough extends Relation
|
|||||||
if ($closure) {
|
if ($closure) {
|
||||||
call_user_func_array($closure, [ & $this->query]);
|
call_user_func_array($closure, [ & $this->query]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->relation($subRelation)->select();
|
return $this->relation($subRelation)->select();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,8 +97,7 @@ class HasManyThrough extends Relation
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class)
|
public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预载入关联查询 返回模型对象
|
* 预载入关联查询 返回模型对象
|
||||||
@@ -110,8 +110,7 @@ class HasManyThrough extends Relation
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class)
|
public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关联统计
|
* 关联统计
|
||||||
@@ -121,8 +120,7 @@ class HasManyThrough extends Relation
|
|||||||
* @return integer
|
* @return integer
|
||||||
*/
|
*/
|
||||||
public function relationCount($result, $closure)
|
public function relationCount($result, $closure)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行基础查询(进执行一次)
|
* 执行基础查询(进执行一次)
|
||||||
|
|||||||
@@ -50,7 +50,10 @@ class HasOne extends OneToOne
|
|||||||
call_user_func_array($closure, [ & $this->query]);
|
call_user_func_array($closure, [ & $this->query]);
|
||||||
}
|
}
|
||||||
// 判断关联类型执行查询
|
// 判断关联类型执行查询
|
||||||
return $this->query->where($this->foreignKey, $this->parent->$localKey)->relation($subRelation)->find();
|
$relationModel = $this->query->where($this->foreignKey, $this->parent->$localKey)->relation($subRelation)->find();
|
||||||
|
$relationModel->setParent(clone $this->parent);
|
||||||
|
|
||||||
|
return $relationModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -56,7 +56,14 @@ class MorphMany extends Relation
|
|||||||
if ($closure) {
|
if ($closure) {
|
||||||
call_user_func_array($closure, [ & $this->query]);
|
call_user_func_array($closure, [ & $this->query]);
|
||||||
}
|
}
|
||||||
return $this->relation($subRelation)->select();
|
$list = $this->relation($subRelation)->select();
|
||||||
|
$parent = clone $this->parent;
|
||||||
|
|
||||||
|
foreach ($list as &$model) {
|
||||||
|
$model->setParent($parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -56,7 +56,10 @@ class MorphOne extends Relation
|
|||||||
if ($closure) {
|
if ($closure) {
|
||||||
call_user_func_array($closure, [ & $this->query]);
|
call_user_func_array($closure, [ & $this->query]);
|
||||||
}
|
}
|
||||||
return $this->relation($subRelation)->find();
|
$relationModel = $this->relation($subRelation)->find();
|
||||||
|
$relationModel->setParent(clone $this->parent);
|
||||||
|
|
||||||
|
return $relationModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -56,8 +56,10 @@ class MorphTo extends Relation
|
|||||||
// 多态模型
|
// 多态模型
|
||||||
$model = $this->parseModel($this->parent->$morphType);
|
$model = $this->parseModel($this->parent->$morphType);
|
||||||
// 主键数据
|
// 主键数据
|
||||||
$pk = $this->parent->$morphKey;
|
$pk = $this->parent->$morphKey;
|
||||||
return (new $model)->relation($subRelation)->find($pk);
|
$relationModel = (new $model)->relation($subRelation)->find($pk);
|
||||||
|
$relationModel->setParent(clone $this->parent);
|
||||||
|
return $relationModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user