mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
改进一对一关联预载入
This commit is contained in:
@@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
namespace think\model\relation;
|
namespace think\model\relation;
|
||||||
|
|
||||||
use think\Exception;
|
|
||||||
use think\Loader;
|
use think\Loader;
|
||||||
use think\Model;
|
use think\Model;
|
||||||
|
|
||||||
@@ -86,12 +85,12 @@ class BelongsTo extends OneToOne
|
|||||||
foreach ($resultSet as $result) {
|
foreach ($resultSet as $result) {
|
||||||
// 关联模型
|
// 关联模型
|
||||||
if (!isset($data[$result->$localKey])) {
|
if (!isset($data[$result->$localKey])) {
|
||||||
throw new Exception('relation data not exists :' . $this->model);
|
$relationModel = null;
|
||||||
} else {
|
} else {
|
||||||
$relationModel = $data[$result->$localKey];
|
$relationModel = $data[$result->$localKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->bindAttr)) {
|
if ($relationModel && !empty($this->bindAttr)) {
|
||||||
// 绑定关联属性
|
// 绑定关联属性
|
||||||
$this->bindAttr($relationModel, $result, $this->bindAttr);
|
$this->bindAttr($relationModel, $result, $this->bindAttr);
|
||||||
}
|
}
|
||||||
@@ -117,11 +116,11 @@ class BelongsTo extends OneToOne
|
|||||||
$data = $this->eagerlyWhere($this, [$localKey => $result->$foreignKey], $localKey, $relation, $subRelation, $closure);
|
$data = $this->eagerlyWhere($this, [$localKey => $result->$foreignKey], $localKey, $relation, $subRelation, $closure);
|
||||||
// 关联模型
|
// 关联模型
|
||||||
if (!isset($data[$result->$localKey])) {
|
if (!isset($data[$result->$localKey])) {
|
||||||
throw new Exception('relation data not exists :' . $this->model);
|
$relationModel = null;
|
||||||
} else {
|
} else {
|
||||||
$relationModel = $data[$result->$localKey];
|
$relationModel = $data[$result->$localKey];
|
||||||
}
|
}
|
||||||
if (!empty($this->bindAttr)) {
|
if ($relationModel && !empty($this->bindAttr)) {
|
||||||
// 绑定关联属性
|
// 绑定关联属性
|
||||||
$this->bindAttr($relationModel, $result, $this->bindAttr);
|
$this->bindAttr($relationModel, $result, $this->bindAttr);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
namespace think\model\relation;
|
namespace think\model\relation;
|
||||||
|
|
||||||
use think\Exception;
|
|
||||||
use think\Loader;
|
use think\Loader;
|
||||||
use think\Model;
|
use think\Model;
|
||||||
|
|
||||||
@@ -113,11 +112,11 @@ class HasOne extends OneToOne
|
|||||||
foreach ($resultSet as $result) {
|
foreach ($resultSet as $result) {
|
||||||
// 关联模型
|
// 关联模型
|
||||||
if (!isset($data[$result->$localKey])) {
|
if (!isset($data[$result->$localKey])) {
|
||||||
throw new Exception('relation data not exists : ' . $this->model);
|
$relationModel = null;
|
||||||
} else {
|
} else {
|
||||||
$relationModel = $data[$result->$localKey];
|
$relationModel = $data[$result->$localKey];
|
||||||
}
|
}
|
||||||
if (!empty($this->bindAttr)) {
|
if ($relationModel && !empty($this->bindAttr)) {
|
||||||
// 绑定关联属性
|
// 绑定关联属性
|
||||||
$this->bindAttr($relationModel, $result, $this->bindAttr);
|
$this->bindAttr($relationModel, $result, $this->bindAttr);
|
||||||
}
|
}
|
||||||
@@ -144,12 +143,12 @@ class HasOne extends OneToOne
|
|||||||
|
|
||||||
// 关联模型
|
// 关联模型
|
||||||
if (!isset($data[$result->$localKey])) {
|
if (!isset($data[$result->$localKey])) {
|
||||||
throw new Exception('relation data not exists :' . $this->model);
|
$relationModel = null;
|
||||||
} else {
|
} else {
|
||||||
$relationModel = $data[$result->$localKey];
|
$relationModel = $data[$result->$localKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->bindAttr)) {
|
if ($relationModel && !empty($this->bindAttr)) {
|
||||||
// 绑定关联属性
|
// 绑定关联属性
|
||||||
$this->bindAttr($relationModel, $result, $this->bindAttr);
|
$this->bindAttr($relationModel, $result, $this->bindAttr);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user