From 1f6cde00eb257d22c97262e6caf2922d8067579c Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Sun, 8 May 2016 19:04:16 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ .../thinkphp/library/think/template/taglib/cxTest.php | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 723ef36f..17a3431d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ +/composer.lock +/vendor .idea \ No newline at end of file diff --git a/tests/thinkphp/library/think/template/taglib/cxTest.php b/tests/thinkphp/library/think/template/taglib/cxTest.php index e40d3de4..34f296a6 100644 --- a/tests/thinkphp/library/think/template/taglib/cxTest.php +++ b/tests/thinkphp/library/think/template/taglib/cxTest.php @@ -47,7 +47,7 @@ EOF; {/volist} EOF; $data = <<\$vo): \$mod = (\$key % 2 );++\$key;?> +\$vo): \$mod = (\$key % 2 );++\$key;?> EOF; @@ -88,9 +88,9 @@ EOF; {/foreach} EOF; $data = <<\$val): ?> +\$val): ?> - + EOF; $cx->parseTag($content); $this->assertEquals($content, $data); @@ -389,7 +389,7 @@ default {/empty} EOF; $data = << +isEmpty())): ?> default EOF; @@ -402,7 +402,7 @@ default {/notempty} EOF; $data = << +isEmpty()))): ?> default EOF; From cdfe0a5e967f3674127d7c36354f8b68da4e556d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 8 May 2016 22:20:17 +0800 Subject: [PATCH 2/4] =?UTF-8?q?Model=E7=B1=BB=E7=9A=84get=E5=92=8Call?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E6=94=AF=E6=8C=81=E7=9B=B4=E6=8E=A5=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=95=B0=E7=BB=84=E6=9D=A1=E4=BB=B6=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=20=E6=94=B9=E8=BF=9Brelation=E7=9A=84=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 14 ++++++++------ library/think/model/Relation.php | 22 +++++++++++----------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index d140d839..9636c8b1 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -598,7 +598,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess protected static function parseQuery(&$data, $with, $cache) { $result = self::with($with)->cache($cache); - if ($data instanceof \Closure) { + if (is_array($data)) { + $result = self::db()->where($data); + } elseif ($data instanceof \Closure) { call_user_func_array($data, [ & $result]); $data = []; } elseif ($data instanceof Query) { @@ -832,19 +834,19 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @access public * @param string $model 模型名 * @param string $table 中间表名 + * @param string $foreignKey 关联外键 * @param string $localKey 当前模型关联键 - * @param string $foreignKey 关联模型关联键 * @return \think\db\Query|string */ - public function belongsToMany($model, $table = '', $localKey = '', $foreignKey = '') + public function belongsToMany($model, $table = '', $foreignKey = '', $localKey = '') { // 记录当前关联信息 $model = $this->parseModel($model); $name = Loader::parseName(basename(str_replace('\\', '/', $model))); $table = $table ?: Db::name(Loader::parseName($this->name) . '_' . $name)->getTable(); - $localKey = $localKey ?: $name . '_id'; - $foreignKey = $foreignKey ?: Loader::parseName($this->name) . '_id'; - return $this->relation->belongsToMany($model, $table, $localKey, $foreignKey); + $foreignKey = $foreignKey ?: $name . '_id'; + $localKey = $localKey ?: Loader::parseName($this->name) . '_id'; + return $this->relation->belongsToMany($model, $table, $foreignKey, $localKey); } /** diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index 5065500b..22223dd2 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -88,7 +88,7 @@ class Relation // 关联查询 $pk = $this->parent->getPk(); $condition['pivot.' . $foreignKey] = $this->parent->$pk; - $result = $this->belongsToManyQuery($relation, $this->middle, $localKey, $foreignKey, $condition)->select(); + $result = $this->belongsToManyQuery($relation, $this->middle, $foreignKey, $localKey, $condition)->select(); foreach ($result as $set) { $pivot = []; foreach ($set->toArray() as $key => $val) { @@ -333,7 +333,7 @@ class Relation $foreignKey = $this->foreignKey; $localKey = $this->localKey; // 预载入关联查询 支持嵌套预载入 - $list = $this->belongsToManyQuery($model, $this->middle, $localKey, $foreignKey, $where)->with($subRelation)->select(); + $list = $this->belongsToManyQuery($model, $this->middle, $foreignKey, $localKey, $where)->with($subRelation)->select(); // 组装模型数据 $data = []; @@ -360,7 +360,7 @@ class Relation * @param string $model 模型名 * @param string $foreignKey 关联外键 * @param string $localKey 关联主键 - * @return \think\db\Query|string + * @return $this */ public function hasOne($model, $foreignKey, $localKey) { @@ -379,7 +379,7 @@ class Relation * @param string $model 模型名 * @param string $foreignKey 关联外键 * @param string $otherKey 关联主键 - * @return \think\db\Query|string + * @return $this */ public function belongsTo($model, $foreignKey, $otherKey) { @@ -399,7 +399,7 @@ class Relation * @param string $model 模型名 * @param string $foreignKey 关联外键 * @param string $localKey 关联主键 - * @return \think\db\Query|string + * @return $this */ public function hasMany($model, $foreignKey, $localKey) { @@ -418,11 +418,11 @@ class Relation * @access public * @param string $model 模型名 * @param string $table 中间表名 + * @param string $foreignKey 关联模型外键 * @param string $localKey 当前模型关联键 - * @param string $foreignKey 关联模型关联键 - * @return \think\db\Query|string + * @return $this */ - public function belongsToMany($model, $table, $localKey, $foreignKey) + public function belongsToMany($model, $table, $foreignKey, $localKey) { // 记录当前关联信息 $this->type = self::BELONGS_TO_MANY; @@ -440,19 +440,19 @@ class Relation * @access public * @param object $model 关联模型对象 * @param string $table 中间表名 - * @param string $localKey 当前模型关联键 * @param string $foreignKey 关联模型关联键 + * @param string $localKey 当前模型关联键 * @param array $condition 关联查询条件 * @return \think\db\Query|string */ - protected function belongsToManyQuery($model, $table, $localKey, $foreignKey, $condition = []) + protected function belongsToManyQuery($model, $table, $foreignKey, $localKey, $condition = []) { // 关联查询封装 $tableName = $model->getTable(); $relationFk = $model->getPk(); return $model::field($tableName . '.*') ->field(true, false, $table, 'pivot', 'pivot__') - ->join($table . ' pivot', 'pivot.' . $localKey . '=' . $tableName . '.' . $relationFk) + ->join($table . ' pivot', 'pivot.' . $foreignKey . '=' . $tableName . '.' . $relationFk) ->where($condition); } From 6136572b6ebcd85e33046724b6ebc4eeef51ba62 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 8 May 2016 22:24:40 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=94=B9=E8=BF=9Bmodel=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index 9636c8b1..31b7c857 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -599,7 +599,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess { $result = self::with($with)->cache($cache); if (is_array($data)) { - $result = self::db()->where($data); + $result = $result->where($data); + $data = []; } elseif ($data instanceof \Closure) { call_user_func_array($data, [ & $result]); $data = []; From 6e9a18955bf83aa83563ff276f9fdc39eaf4e502 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 8 May 2016 22:42:43 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Model=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index 31b7c857..f0c693a4 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -598,7 +598,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess protected static function parseQuery(&$data, $with, $cache) { $result = self::with($with)->cache($cache); - if (is_array($data)) { + if (is_array($data) && key($data) !== 0) { $result = $result->where($data); $data = []; } elseif ($data instanceof \Closure) {