diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index 48d7851f..4ce20411 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -604,7 +604,8 @@ class Relation if (is_array($data)) { // 保存关联表数据 $model = new $this->model; - $id = $model->save($data); + $model->save($data); + $id = $model->getLastInsID(); } elseif (is_numeric($data) || is_string($data)) { // 根据关联表主键直接写入中间表 $id = $data; @@ -681,11 +682,14 @@ class Relation $pk = (new $this->model)->getPk(); $throughKey = $this->throughKey; $modelTable = $this->parent->getTable(); - $result = $this->query->field($alias . '.*')->alias($alias) + $this->query->field($alias . '.*')->alias($alias) ->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey) ->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey) ->where($throughTable . '.' . $this->foreignKey, $this->parent->{$this->localKey}); break; + case self::BELONGS_TO_MANY: + // TODO + } $result = call_user_func_array([$this->query, $method], $args); if ($result instanceof \think\db\Query) {