改进一对一关联预载入查询 支持使用IN方式 一对一关联类增加setEagerlyType方法用于设置预载入查询方式 默认为JOIN方式,setEagerlyType(1) 使用IN方式

Loader类的parseName方法增加第三个参数 用于驼峰法转换是否首字母大写
This commit is contained in:
thinkphp
2016-12-13 11:43:26 +08:00
parent 8e8355e2d8
commit 082b3bea81
6 changed files with 222 additions and 30 deletions

View File

@@ -27,8 +27,7 @@ use think\exception\PDOException;
use think\Loader;
use think\Model;
use think\model\Relation;
use think\model\relation\BelongsTo;
use think\model\relation\HasOne;
use think\model\relation\OneToOne;
use think\Paginator;
class Query
@@ -1653,9 +1652,9 @@ class Query
}
/** @var Relation $model */
$relation = Loader::parseName($relation, 1);
$relation = Loader::parseName($relation, 1, false);
$model = $class->$relation();
if ($model instanceof HasOne || $model instanceof BelongsTo) {
if ($model instanceof OneToOne && 0 == $model->getEagerlyType()) {
$model->eagerly($this, $relation, $subRelation, $closure, $first);
$first = false;
} elseif ($closure) {