From 02934b0d27708b098f34811587a825de6db52192 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 20 Apr 2016 15:31:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=85=B3=E8=81=94=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=E5=85=B3=E8=81=94=E9=94=AE=E5=80=BC=E5=92=8C?= =?UTF-8?q?=E8=A1=A8=E5=90=8D=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 7 ++++--- library/think/db/Query.php | 4 ++-- library/think/model/Relation.php | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 7707384a..c93a86e0 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -862,9 +862,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess { // 记录当前关联信息 $model = $this->parseModel($model); - $table = $table ?: Db::name(strtolower($this->name . '_' . basename(str_replace('\\', '/', $model))))->getTableName(); - $localKey = $localKey ?: Loader::parseName(basename(str_replace('\\', '/', $model))) . '_id'; - $foreignKey = $foreignKey ?: strtolower($this->name) . '_id'; + $name = Loader::parseName(basename(str_replace('\\', '/', $model))); + $table = $table ?: Db::name(Loader::parseName($this->name) . '_' . $name)->getTableName(); + $localKey = $localKey ?: $name . '_id'; + $foreignKey = $foreignKey ?: Loader::parseName($this->name) . '_id'; return $this->relation->belongsToMany($model, $table, $localKey, $foreignKey); } diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 7195e6c4..d042b8a2 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -845,13 +845,13 @@ class Query $info = $class->getRelationInfo(); if (in_array($info['type'], [Relation::HAS_ONE, Relation::BELONGS_TO])) { if (0 == $i) { - $joinName = strtolower(basename(str_replace('\\', '/', $this->options['model']))); + $joinName = Loader::parseName(basename(str_replace('\\', '/', $this->options['model']))); $joinTable = $this->connection->getTableName(); $this->table($joinTable)->alias($joinName)->field(true, false, $joinTable, $joinName); } // 预载入封装 $table = $info['model']::getTableName(); - $name = strtolower(basename(str_replace('\\', '/', $info['model']))); + $name = Loader::parseName(basename(str_replace('\\', '/', $info['model']))); $this->via($name); $this->join($table . ' ' . $name, $joinName . '.' . $info['localKey'] . '=' . $name . '.' . $info['foreignKey'])->field(true, false, $table, $name, $name . '__'); if ($closure) { diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index 674510cb..38351ccf 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -13,6 +13,7 @@ namespace think\model; use think\Db; use think\Exception; +use think\Loader; use think\model\Pivot; class Relation @@ -257,7 +258,7 @@ class Relation */ protected function match($model, $relation, &$result) { - $modelName = strtolower(basename(str_replace('\\', '/', $model))); + $modelName = Loader::parseName(basename(str_replace('\\', '/', $model))); // 重新组装模型数据 foreach ($result->toArray() as $key => $val) { if (strpos($key, '__')) {