From 3a78c93d11198c0e4de7ea06e9358165532309c9 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Dec 2016 17:55:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BRoute=E7=B1=BBsetRule?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20=E4=BF=AE=E6=AD=A3BelongsToMany=E7=B1=BB?= =?UTF-8?q?=E7=9A=84attach=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 6 ++++-- library/think/model/relation/BelongsToMany.php | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 41da4652..735e6ef0 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -296,12 +296,14 @@ class Route } elseif ('$' == substr($rule, -1, 1)) { // 是否完整匹配 $option['complete_match'] = true; - $rule = substr($rule, 0, -1); } } elseif (empty($option['complete_match']) && '$' == substr($rule, -1, 1)) { // 是否完整匹配 $option['complete_match'] = true; - $rule = substr($rule, 0, -1); + } + + if (true == $option['complete_match'] && '$' == substr($rule, -1, 1)) { + $rule = substr($rule, 0, -1); } if ('/' != $rule || $group) { diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index 93df01cf..a07de2d7 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -13,6 +13,7 @@ namespace think\model\relation; use think\Db; use think\db\Query; +use think\Exception; use think\Model; use think\model\Pivot; use think\model\Relation; @@ -269,7 +270,7 @@ class BelongsToMany extends Relation $pk = $this->parent->getPk(); $pivot[$this->localKey] = $this->parent->$pk; $pivot[$this->foreignKey] = $id; - return $this->query->table($this->middle)->insert($pivot); + return $this->query->table($this->middle)->insert($pivot, true); } else { throw new Exception('miss relation data'); }