mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 15:42:48 +08:00
改进MorphTo关联
This commit is contained in:
@@ -238,17 +238,18 @@ class MorphTo extends Relation
|
|||||||
/**
|
/**
|
||||||
* 添加关联数据
|
* 添加关联数据
|
||||||
* @access public
|
* @access public
|
||||||
* @param Model $model 关联模型对象
|
* @param Model $model 关联模型对象
|
||||||
|
* @param string $type 多态类型
|
||||||
* @return Model
|
* @return Model
|
||||||
*/
|
*/
|
||||||
public function associate($model)
|
public function associate($model, $type = '')
|
||||||
{
|
{
|
||||||
$morphKey = $this->morphKey;
|
$morphKey = $this->morphKey;
|
||||||
$morphType = $this->morphType;
|
$morphType = $this->morphType;
|
||||||
$pk = $model->getPk();
|
$pk = $model->getPk();
|
||||||
|
|
||||||
$this->parent->setAttr($morphKey, $model->$pk);
|
$this->parent->setAttr($morphKey, $model->$pk);
|
||||||
$this->parent->setAttr($morphType, get_class($model));
|
$this->parent->setAttr($morphType, $type ?: get_class($model));
|
||||||
$this->parent->save();
|
$this->parent->save();
|
||||||
|
|
||||||
return $this->parent->setRelation($this->relation, $model);
|
return $this->parent->setRelation($this->relation, $model);
|
||||||
|
|||||||
Reference in New Issue
Block a user