关联查询支持远程一对多关联 Query类view方法的field参数支持传入true

This commit is contained in:
thinkphp
2016-05-25 17:57:50 +08:00
parent 62b01bf566
commit e890d43d55
3 changed files with 92 additions and 16 deletions

View File

@@ -885,6 +885,28 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
return $this->relation()->hasMany($model, $foreignKey, $localKey, $alias);
}
/**
* HAS MANY 远程关联定义
* @access public
* @param string $model 模型名
* @param string $through 中间模型名
* @param string $foreignKey 关联外键
* @param string $throughKey 关联外键
* @param string $localKey 关联主键
* @param array $alias 别名定义
* @return \think\db\Query|string
*/
public function hasManyThrough($model,$through,$foreignKey='',$throughKey='',$localKey='',$alias=[]){
// 记录当前关联信息
$model = $this->parseModel($model);
$through = $this->parseModel($through);
$localKey = $localKey ?: $this->getPk();
$foreignKey = $foreignKey ?: Loader::parseName($this->name) . '_id';
$name = Loader::parseName(basename(str_replace('\\', '/', $through)));
$throughKey = $throughKey ?: $name . '_id';
return $this->relation()->hasManyThrough($model, $through,$foreignKey,$throughKey, $localKey, $alias);
}
/**
* BELONGS TO MANY 关联定义
* @access public