From fcde43a1b0e049f37b2750b9d69482fb45084580 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 21 Sep 2016 12:08:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=85=B3=E8=81=94=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=20=E5=A4=9A=E5=AF=B9=E5=A4=9Asave=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=B8=80=E5=A4=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/Relation.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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) {