thinkphp框架升级

This commit is contained in:
devil_gong
2019-11-11 14:37:00 +08:00
parent 27540686b3
commit 820030d987
55 changed files with 844 additions and 341 deletions

View File

@ -11,6 +11,7 @@
namespace think\model\relation;
use Closure;
use think\db\Query;
use think\Loader;
use think\Model;
@ -48,7 +49,7 @@ class HasMany extends Relation
*/
public function getRelation($subRelation = '', $closure = null)
{
if ($closure) {
if ($closure instanceof Closure) {
$closure($this->query);
}
@ -163,7 +164,7 @@ class HasMany extends Relation
return 0;
}
if ($closure) {
if ($closure instanceof Closure) {
$return = $closure($this->query);
if ($return && is_string($return)) {
$name = $return;
@ -186,7 +187,7 @@ class HasMany extends Relation
*/
public function getRelationCountQuery($closure, $aggregate = 'count', $field = '*', &$aggregateAlias = '')
{
if ($closure) {
if ($closure instanceof Closure) {
$return = $closure($this->query);
if ($return && is_string($return)) {
@ -194,8 +195,8 @@ class HasMany extends Relation
}
}
return $this->query
->whereExp($this->foreignKey, '=' . $this->parent->getTable() . '.' . $this->localKey)
return $this->query->alias($aggregate . '_table')
->whereExp($aggregate . '_table.' . $this->foreignKey, '=' . $this->parent->getTable() . '.' . $this->localKey)
->fetchSql()
->$aggregate($field);
}
@ -216,7 +217,7 @@ class HasMany extends Relation
$this->query->removeWhereField($this->foreignKey);
// 预载入关联查询 支持嵌套预载入
if ($closure) {
if ($closure instanceof Closure) {
$closure($this->query);
}
@ -266,11 +267,11 @@ class HasMany extends Relation
/**
* 批量保存当前关联数据对象
* @access public
* @param array $dataSet 数据集
* @param array|\think\Collection $dataSet 数据集
* @param boolean $replace 是否自动识别更新和写入
* @return array|false
*/
public function saveAll(array $dataSet, $replace = true)
public function saveAll($dataSet, $replace = true)
{
$result = [];
@ -292,14 +293,18 @@ class HasMany extends Relation
*/
public function has($operator = '>=', $count = 1, $id = '*', $joinType = 'INNER')
{
$table = $this->query->getTable();
$model = basename(str_replace('\\', '/', get_class($this->parent)));
$relation = basename(str_replace('\\', '/', $this->model));
$table = $this->query->getTable();
$model = basename(str_replace('\\', '/', get_class($this->parent)));
$relation = basename(str_replace('\\', '/', $this->model));
$softDelete = $this->query->getOptions('soft_delete');
return $this->parent->db()
->alias($model)
->field($model . '.*')
->join([$table => $relation], $model . '.' . $this->localKey . '=' . $relation . '.' . $this->foreignKey, $joinType)
->when($softDelete, function ($query) use ($softDelete, $relation) {
$query->where($relation . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null);
})
->group($relation . '.' . $this->foreignKey)
->having('count(' . $id . ')' . $operator . $count);
}
@ -321,13 +326,17 @@ class HasMany extends Relation
$this->getQueryWhere($where, $relation);
}
$fields = $this->getRelationQueryFields($fields, $model);
$fields = $this->getRelationQueryFields($fields, $model);
$softDelete = $this->query->getOptions('soft_delete');
return $this->parent->db()
->alias($model)
->group($model . '.' . $this->localKey)
->field($fields)
->join([$table => $relation], $model . '.' . $this->localKey . '=' . $relation . '.' . $this->foreignKey)
->when($softDelete, function ($query) use ($softDelete, $relation) {
$query->where($relation . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null);
})
->where($where);
}