mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 23:02:48 +08:00
取消关联类无效的alias参数 仅morphTo关联保留 用于设置多态别名
This commit is contained in:
@@ -25,8 +25,6 @@ abstract class Relation
|
||||
protected $foreignKey;
|
||||
// 关联表主键
|
||||
protected $localKey;
|
||||
// 数据表别名
|
||||
protected $alias;
|
||||
// 当前关联的JOIN类型
|
||||
protected $joinType;
|
||||
// 关联模型查询对象
|
||||
@@ -80,18 +78,6 @@ abstract class Relation
|
||||
return $class ? new $class($resultSet) : $resultSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前关联定义的数据表别名
|
||||
* @access public
|
||||
* @param array $alias 别名定义
|
||||
* @return $this
|
||||
*/
|
||||
public function setAlias($alias)
|
||||
{
|
||||
$this->alias = $alias;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除关联查询参数
|
||||
* @access public
|
||||
|
||||
@@ -22,16 +22,14 @@ class BelongsTo extends OneToOne
|
||||
* @param string $model 模型名
|
||||
* @param string $foreignKey 关联外键
|
||||
* @param string $localKey 关联主键
|
||||
* @param array $alias 别名定义
|
||||
* @param string $joinType JOIN类型
|
||||
*/
|
||||
public function __construct(Model $parent, $model, $foreignKey, $localKey, $alias = [], $joinType = 'INNER')
|
||||
public function __construct(Model $parent, $model, $foreignKey, $localKey, $joinType = 'INNER')
|
||||
{
|
||||
$this->parent = $parent;
|
||||
$this->model = $model;
|
||||
$this->foreignKey = $foreignKey;
|
||||
$this->localKey = $localKey;
|
||||
$this->alias = $alias;
|
||||
$this->joinType = $joinType;
|
||||
$this->query = (new $model)->db();
|
||||
}
|
||||
|
||||
@@ -31,16 +31,14 @@ class BelongsToMany extends Relation
|
||||
* @param string $table 中间表名
|
||||
* @param string $foreignKey 关联模型外键
|
||||
* @param string $localKey 当前模型关联键
|
||||
* @param array $alias 别名定义
|
||||
*/
|
||||
public function __construct(Model $parent, $model, $table, $foreignKey, $localKey, $alias = [])
|
||||
public function __construct(Model $parent, $model, $table, $foreignKey, $localKey)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
$this->model = $model;
|
||||
$this->foreignKey = $foreignKey;
|
||||
$this->localKey = $localKey;
|
||||
$this->middle = $table;
|
||||
$this->alias = $alias;
|
||||
$this->query = (new $model)->db();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,15 +25,13 @@ class HasMany extends Relation
|
||||
* @param string $model 模型名
|
||||
* @param string $foreignKey 关联外键
|
||||
* @param string $localKey 关联主键
|
||||
* @param array $alias 别名定义
|
||||
*/
|
||||
public function __construct(Model $parent, $model, $foreignKey, $localKey, $alias = [])
|
||||
public function __construct(Model $parent, $model, $foreignKey, $localKey)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
$this->model = $model;
|
||||
$this->foreignKey = $foreignKey;
|
||||
$this->localKey = $localKey;
|
||||
$this->alias = $alias;
|
||||
$this->query = (new $model)->db();
|
||||
}
|
||||
|
||||
|
||||
@@ -33,9 +33,8 @@ class HasManyThrough extends Relation
|
||||
* @param string $firstkey 关联外键
|
||||
* @param string $secondKey 关联外键
|
||||
* @param string $localKey 关联主键
|
||||
* @param array $alias 别名定义
|
||||
*/
|
||||
public function __construct(Model $parent, $model, $through, $foreignKey, $throughKey, $localKey, $alias = [])
|
||||
public function __construct(Model $parent, $model, $through, $foreignKey, $throughKey, $localKey)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
$this->model = $model;
|
||||
@@ -43,7 +42,6 @@ class HasManyThrough extends Relation
|
||||
$this->foreignKey = $foreignKey;
|
||||
$this->throughKey = $throughKey;
|
||||
$this->localKey = $localKey;
|
||||
$this->alias = $alias;
|
||||
$this->query = (new $model)->db();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,16 +22,14 @@ class HasOne extends OneToOne
|
||||
* @param string $model 模型名
|
||||
* @param string $foreignKey 关联外键
|
||||
* @param string $localKey 关联主键
|
||||
* @param array $alias 别名定义
|
||||
* @param string $joinType JOIN类型
|
||||
*/
|
||||
public function __construct(Model $parent, $model, $foreignKey, $localKey, $alias = [], $joinType = 'INNER')
|
||||
public function __construct(Model $parent, $model, $foreignKey, $localKey, $joinType = 'INNER')
|
||||
{
|
||||
$this->parent = $parent;
|
||||
$this->model = $model;
|
||||
$this->foreignKey = $foreignKey;
|
||||
$this->localKey = $localKey;
|
||||
$this->alias = $alias;
|
||||
$this->joinType = $joinType;
|
||||
$this->query = (new $model)->db();
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ class MorphTo extends Relation
|
||||
// 多态字段
|
||||
protected $morphKey;
|
||||
protected $morphType;
|
||||
// 多态别名
|
||||
protected $alias;
|
||||
|
||||
/**
|
||||
* 架构函数
|
||||
@@ -74,6 +76,18 @@ class MorphTo extends Relation
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置多态别名
|
||||
* @access public
|
||||
* @param array $alias 别名定义
|
||||
* @return $this
|
||||
*/
|
||||
public function setAlias($alias)
|
||||
{
|
||||
$this->alias = $alias;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 预载入关联查询
|
||||
* @access public
|
||||
|
||||
@@ -37,7 +37,7 @@ abstract class OneToOne extends Relation
|
||||
public function eagerly(Query $query, $relation, $subRelation, $closure, $first)
|
||||
{
|
||||
$name = Loader::parseName(basename(str_replace('\\', '/', $query->getModel())));
|
||||
$alias = isset($this->alias[$name]) ? $this->alias[$name] : $name;
|
||||
$alias = $name;
|
||||
if ($first) {
|
||||
$table = $query->getTable();
|
||||
$query->table([$table => $alias]);
|
||||
@@ -53,7 +53,7 @@ abstract class OneToOne extends Relation
|
||||
// 预载入封装
|
||||
$joinTable = $this->query->getTable();
|
||||
$joinName = Loader::parseName(basename(str_replace('\\', '/', $this->model)));
|
||||
$joinAlias = isset($this->alias[$joinName]) ? $this->alias[$joinName] : $relation;
|
||||
$joinAlias = $relation;
|
||||
$query->via($joinAlias);
|
||||
|
||||
if ($this instanceof BelongsTo) {
|
||||
|
||||
Reference in New Issue
Block a user