mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
多态一对多关联方法参数调整
This commit is contained in:
@@ -1367,31 +1367,39 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
* MORPH MANY 关联定义
|
* MORPH MANY 关联定义
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $model 模型名
|
* @param string $model 模型名
|
||||||
* @param string $id 关联外键
|
* @param string|array $morph 多态字段信息
|
||||||
* @param string $morphType 多态字段名
|
|
||||||
* @param string $type 多态类型
|
* @param string $type 多态类型
|
||||||
* @return Relation
|
* @return Relation
|
||||||
*/
|
*/
|
||||||
public function morphMany($model, $id, $morphType = '', $type = '')
|
public function morphMany($model, $morph, $type = '')
|
||||||
{
|
{
|
||||||
// 记录当前关联信息
|
// 记录当前关联信息
|
||||||
$model = $this->parseModel($model);
|
$model = $this->parseModel($model);
|
||||||
$type = $type ?: Loader::parseName($this->name);
|
$type = $type ?: Loader::parseName($this->name);
|
||||||
$name = Loader::parseName(basename(str_replace('\\', '/', $model)));
|
if (is_array($morph)) {
|
||||||
$morphType = $morphType ?: Loader::parseName($name) . '_type';
|
list($foreignKey, $morphType) = $morph;
|
||||||
return $this->relation()->morphMany($model, $id, $morphType, $type);
|
} else {
|
||||||
|
$morphType = $morph . '_type';
|
||||||
|
$foreignKey = $morph . '_id';
|
||||||
|
}
|
||||||
|
return $this->relation()->morphMany($model, $foreignKey, $morphType, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MORPH TO 关联定义
|
* MORPH TO 关联定义
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $morphType 多态字段名
|
* @param string|array $morph 多态字段信息
|
||||||
* @param string $foreignKey 外键名
|
|
||||||
* @return Relation
|
* @return Relation
|
||||||
*/
|
*/
|
||||||
public function morphTo($morphType, $foreignKey)
|
public function morphTo($morph)
|
||||||
{
|
{
|
||||||
// 记录当前关联信息
|
// 记录当前关联信息
|
||||||
|
if (is_array($morph)) {
|
||||||
|
list($foreignKey, $morphType) = $morph;
|
||||||
|
} else {
|
||||||
|
$morphType = $morph . '_type';
|
||||||
|
$foreignKey = $morph . '_id';
|
||||||
|
}
|
||||||
return $this->relation()->morphTo($morphType, $foreignKey);
|
return $this->relation()->morphTo($morphType, $foreignKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user