From 02f36421d044991b7de7d80af3c46e8bf900b549 Mon Sep 17 00:00:00 2001 From: gongfuxiang Date: Mon, 24 Jan 2022 15:13:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B1=BB=E5=BA=93=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vendor/composer/autoload_psr4.php | 2 +- vendor/composer/autoload_static.php | 6 +- vendor/composer/installed.json | 28 +++++----- vendor/composer/installed.php | 16 +++--- vendor/services.php | 2 +- vendor/topthink/framework/src/think/App.php | 2 +- vendor/topthink/framework/src/think/Env.php | 2 +- .../framework/src/think/cache/Driver.php | 2 +- .../src/think/console/input/Option.php | 28 +++++----- .../framework/src/think/route/Resource.php | 2 +- .../framework/src/think/route/Rule.php | 18 ++++++ .../framework/src/think/route/RuleItem.php | 4 +- vendor/topthink/think-orm/src/db/Fetch.php | 6 +- .../think-orm/src/db/builder/Sqlite.php | 24 ++++---- .../think-orm/src/db/connector/Sqlite.php | 2 +- .../think-orm/src/model/concern/Attribute.php | 3 + .../src/model/relation/BelongsTo.php | 11 ++-- .../src/model/relation/BelongsToMany.php | 56 +++++++++---------- .../src/model/relation/HasManyThrough.php | 8 ++- .../think-orm/src/model/relation/HasOne.php | 10 ++-- 20 files changed, 130 insertions(+), 102 deletions(-) diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php index b5c204828..9edf7e966 100644 --- a/vendor/composer/autoload_psr4.php +++ b/vendor/composer/autoload_psr4.php @@ -9,7 +9,7 @@ return array( 'think\\view\\driver\\' => array($vendorDir . '/topthink/think-view/src'), 'think\\trace\\' => array($vendorDir . '/topthink/think-trace/src'), 'think\\app\\' => array($vendorDir . '/topthink/think-multi-app/src'), - 'think\\' => array($vendorDir . '/topthink/framework/src/think', $vendorDir . '/topthink/think-helper/src', $vendorDir . '/topthink/think-orm/src', $vendorDir . '/topthink/think-template/src'), + 'think\\' => array($vendorDir . '/topthink/think-helper/src', $vendorDir . '/topthink/think-template/src', $vendorDir . '/topthink/think-orm/src', $vendorDir . '/topthink/framework/src/think'), 'app\\' => array($baseDir . '/app'), 'ZipStream\\' => array($vendorDir . '/maennchen/zipstream-php/src'), 'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'), diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 98b6761cc..9170ac6ba 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -81,10 +81,10 @@ class ComposerStaticInit1ed187777399b73a018d9a6af63a57d1 ), 'think\\' => array ( - 0 => __DIR__ . '/..' . '/topthink/framework/src/think', - 1 => __DIR__ . '/..' . '/topthink/think-helper/src', + 0 => __DIR__ . '/..' . '/topthink/think-helper/src', + 1 => __DIR__ . '/..' . '/topthink/think-template/src', 2 => __DIR__ . '/..' . '/topthink/think-orm/src', - 3 => __DIR__ . '/..' . '/topthink/think-template/src', + 3 => __DIR__ . '/..' . '/topthink/framework/src/think', ), 'app\\' => array ( diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 886d80cde..6a2cbb377 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -1441,17 +1441,17 @@ }, { "name": "topthink/framework", - "version": "v6.0.11", - "version_normalized": "6.0.11.0", + "version": "v6.0.12", + "version_normalized": "6.0.12.0", "source": { "type": "git", "url": "https://github.com/top-think/framework.git", - "reference": "d9cadb6971ae92ff85ba5f2be77a40b0ad5718fb" + "reference": "e478316ac843c1a884a3b3a7a94db17c4001ff5c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/top-think/framework/zipball/d9cadb6971ae92ff85ba5f2be77a40b0ad5718fb", - "reference": "d9cadb6971ae92ff85ba5f2be77a40b0ad5718fb", + "url": "https://api.github.com/repos/top-think/framework/zipball/e478316ac843c1a884a3b3a7a94db17c4001ff5c", + "reference": "e478316ac843c1a884a3b3a7a94db17c4001ff5c", "shasum": "", "mirrors": [ { @@ -1479,7 +1479,7 @@ "mockery/mockery": "^1.2", "phpunit/phpunit": "^7.0" }, - "time": "2021-12-31T09:14:28+00:00", + "time": "2022-01-21T06:31:07+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -1511,7 +1511,7 @@ ], "support": { "issues": "https://github.com/top-think/framework/issues", - "source": "https://github.com/top-think/framework/tree/v6.0.11" + "source": "https://github.com/top-think/framework/tree/v6.0.12" }, "install-path": "../topthink/framework" }, @@ -1623,17 +1623,17 @@ }, { "name": "topthink/think-orm", - "version": "v2.0.50", - "version_normalized": "2.0.50.0", + "version": "v2.0.51", + "version_normalized": "2.0.51.0", "source": { "type": "git", "url": "https://github.com/top-think/think-orm.git", - "reference": "091ad5e023c15fcce4ceaea2f3814bdf71045cde" + "reference": "149d266acdc4b2f07c6a94f1733b6b97d340e0e2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/top-think/think-orm/zipball/091ad5e023c15fcce4ceaea2f3814bdf71045cde", - "reference": "091ad5e023c15fcce4ceaea2f3814bdf71045cde", + "url": "https://api.github.com/repos/top-think/think-orm/zipball/149d266acdc4b2f07c6a94f1733b6b97d340e0e2", + "reference": "149d266acdc4b2f07c6a94f1733b6b97d340e0e2", "shasum": "", "mirrors": [ { @@ -1653,7 +1653,7 @@ "require-dev": { "phpunit/phpunit": "^7|^8|^9.5" }, - "time": "2022-01-06T02:48:16+00:00", + "time": "2022-01-21T06:25:25+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -1681,7 +1681,7 @@ ], "support": { "issues": "https://github.com/top-think/think-orm/issues", - "source": "https://github.com/top-think/think-orm/tree/v2.0.50" + "source": "https://github.com/top-think/think-orm/tree/v2.0.51" }, "install-path": "../topthink/think-orm" }, diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 8fb27e223..76ed4be63 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -5,7 +5,7 @@ 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), - 'reference' => '5979814ba42ca1796f517662de1e19f6736a1182', + 'reference' => '921d28f9ce7fcc47b9b8312f92080643eddfe75a', 'name' => 'shopxo/shopxo', 'dev' => true, ), @@ -160,7 +160,7 @@ 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), - 'reference' => '5979814ba42ca1796f517662de1e19f6736a1182', + 'reference' => '921d28f9ce7fcc47b9b8312f92080643eddfe75a', 'dev_requirement' => false, ), 'symfony/polyfill-mbstring' => array( @@ -200,12 +200,12 @@ 'dev_requirement' => true, ), 'topthink/framework' => array( - 'pretty_version' => 'v6.0.11', - 'version' => '6.0.11.0', + 'pretty_version' => 'v6.0.12', + 'version' => '6.0.12.0', 'type' => 'library', 'install_path' => __DIR__ . '/../topthink/framework', 'aliases' => array(), - 'reference' => 'd9cadb6971ae92ff85ba5f2be77a40b0ad5718fb', + 'reference' => 'e478316ac843c1a884a3b3a7a94db17c4001ff5c', 'dev_requirement' => false, ), 'topthink/think-helper' => array( @@ -227,12 +227,12 @@ 'dev_requirement' => false, ), 'topthink/think-orm' => array( - 'pretty_version' => 'v2.0.50', - 'version' => '2.0.50.0', + 'pretty_version' => 'v2.0.51', + 'version' => '2.0.51.0', 'type' => 'library', 'install_path' => __DIR__ . '/../topthink/think-orm', 'aliases' => array(), - 'reference' => '091ad5e023c15fcce4ceaea2f3814bdf71045cde', + 'reference' => '149d266acdc4b2f07c6a94f1733b6b97d340e0e2', 'dev_requirement' => false, ), 'topthink/think-template' => array( diff --git a/vendor/services.php b/vendor/services.php index c8d12dfed..e6056e741 100644 --- a/vendor/services.php +++ b/vendor/services.php @@ -1,5 +1,5 @@ 'think\\app\\Service', diff --git a/vendor/topthink/framework/src/think/App.php b/vendor/topthink/framework/src/think/App.php index 101bb6d64..073a41adf 100644 --- a/vendor/topthink/framework/src/think/App.php +++ b/vendor/topthink/framework/src/think/App.php @@ -39,7 +39,7 @@ use think\initializer\RegisterService; */ class App extends Container { - const VERSION = '6.0.10LTS'; + const VERSION = '6.0.12LTS'; /** * 应用调试模式 diff --git a/vendor/topthink/framework/src/think/Env.php b/vendor/topthink/framework/src/think/Env.php index 1046bc484..9e1b7f4b9 100644 --- a/vendor/topthink/framework/src/think/Env.php +++ b/vendor/topthink/framework/src/think/Env.php @@ -188,7 +188,7 @@ class Env implements ArrayAccess } #[\ReturnTypeWillChange] - public function offsetUnset($name) + public function offsetUnset($name): void { throw new Exception('not support: unset'); } diff --git a/vendor/topthink/framework/src/think/cache/Driver.php b/vendor/topthink/framework/src/think/cache/Driver.php index 5813c7b34..37ffbc9e7 100644 --- a/vendor/topthink/framework/src/think/cache/Driver.php +++ b/vendor/topthink/framework/src/think/cache/Driver.php @@ -249,7 +249,7 @@ abstract class Driver implements CacheInterface, CacheHandlerInterface * @param string $data 缓存数据 * @return mixed */ - protected function unserialize(string $data) + protected function unserialize($data) { if (is_numeric($data)) { return $data; diff --git a/vendor/topthink/framework/src/think/console/input/Option.php b/vendor/topthink/framework/src/think/console/input/Option.php index 19c7e1e86..d7e651442 100644 --- a/vendor/topthink/framework/src/think/console/input/Option.php +++ b/vendor/topthink/framework/src/think/console/input/Option.php @@ -18,7 +18,7 @@ namespace think\console\input; class Option { // 无需传值 - const VALUE_NONE = 1; + const VALUE_NONE = 1; // 必须传值 const VALUE_REQUIRED = 2; // 可选传值 @@ -30,13 +30,13 @@ class Option * 选项名 * @var string */ - private $name; + private $name = ''; /** * 选项短名称 * @var string */ - private $shortcut; + private $shortcut = ''; /** * 选项类型 @@ -54,7 +54,7 @@ class Option * 选项描述 * @var string */ - private $description; + private $description = ''; /** * 构造方法 @@ -76,10 +76,10 @@ class Option } if (empty($shortcut)) { - $shortcut = null; + $shortcut = ''; } - if (null !== $shortcut) { + if ('' !== $shortcut) { if (is_array($shortcut)) { $shortcut = implode('|', $shortcut); } @@ -114,7 +114,7 @@ class Option * 获取短名称 * @return string */ - public function getShortcut() + public function getShortcut(): string { return $this->shortcut; } @@ -123,7 +123,7 @@ class Option * 获取选项名 * @return string */ - public function getName() + public function getName(): string { return $this->name; } @@ -132,7 +132,7 @@ class Option * 是否可以设置值 * @return bool 类型不是 self::VALUE_NONE 的时候返回true,其他均返回false */ - public function acceptValue() + public function acceptValue(): bool { return $this->isValueRequired() || $this->isValueOptional(); } @@ -141,7 +141,7 @@ class Option * 是否必须 * @return bool 类型是 self::VALUE_REQUIRED 的时候返回true,其他均返回false */ - public function isValueRequired() + public function isValueRequired(): bool { return self::VALUE_REQUIRED === (self::VALUE_REQUIRED & $this->mode); } @@ -150,7 +150,7 @@ class Option * 是否可选 * @return bool 类型是 self::VALUE_OPTIONAL 的时候返回true,其他均返回false */ - public function isValueOptional() + public function isValueOptional(): bool { return self::VALUE_OPTIONAL === (self::VALUE_OPTIONAL & $this->mode); } @@ -159,7 +159,7 @@ class Option * 选项值是否接受数组 * @return bool 类型是 self::VALUE_IS_ARRAY 的时候返回true,其他均返回false */ - public function isArray() + public function isArray(): bool { return self::VALUE_IS_ARRAY === (self::VALUE_IS_ARRAY & $this->mode); } @@ -199,7 +199,7 @@ class Option * 获取描述文字 * @return string */ - public function getDescription() + public function getDescription(): string { return $this->description; } @@ -209,7 +209,7 @@ class Option * @param Option $option * @return bool */ - public function equals(Option $option) + public function equals(Option $option): bool { return $option->getName() === $this->getName() && $option->getShortcut() === $this->getShortcut() diff --git a/vendor/topthink/framework/src/think/route/Resource.php b/vendor/topthink/framework/src/think/route/Resource.php index bb37cb6d9..5185cdc35 100644 --- a/vendor/topthink/framework/src/think/route/Resource.php +++ b/vendor/topthink/framework/src/think/route/Resource.php @@ -213,7 +213,7 @@ class Resource extends RuleGroup } /** - * 绑定资源模型 + * 绑定资源中间件 * @access public * @param array|string $name 资源类型或者中间件定义 * @param array|string $middleware 中间件定义 diff --git a/vendor/topthink/framework/src/think/route/Rule.php b/vendor/topthink/framework/src/think/route/Rule.php index 31b2e0e59..2d864cd25 100644 --- a/vendor/topthink/framework/src/think/route/Rule.php +++ b/vendor/topthink/framework/src/think/route/Rule.php @@ -532,6 +532,17 @@ abstract class Rule return $this->setOption('view', $view); } + /** + * 通过闭包检查路由是否匹配 + * @access public + * @param callable $match 闭包 + * @return $this + */ + public function match(callable $match) + { + return $this->setOption('match', $match); + } + /** * 设置路由完整匹配 * @access public @@ -694,6 +705,13 @@ abstract class Rule */ protected function checkOption(array $option, Request $request): bool { + // 检查当前路由是否匹配 + if (isset($option['match']) && is_callable($option['match'])) { + if (false === $option['match']($this, $request)) { + return false; + } + } + // 请求类型检测 if (!empty($option['method'])) { if (is_string($option['method']) && false === stripos($option['method'], $request->method())) { diff --git a/vendor/topthink/framework/src/think/route/RuleItem.php b/vendor/topthink/framework/src/think/route/RuleItem.php index 1f9aa52a1..e4e324689 100644 --- a/vendor/topthink/framework/src/think/route/RuleItem.php +++ b/vendor/topthink/framework/src/think/route/RuleItem.php @@ -196,7 +196,7 @@ class RuleItem extends Rule $url = $this->urlSuffixCheck($request, $url, $option); if (is_null($match)) { - $match = $this->match($url, $option, $pattern, $completeMatch); + $match = $this->checkMatch($url, $option, $pattern, $completeMatch); } if (false !== $match) { @@ -252,7 +252,7 @@ class RuleItem extends Rule * @param bool $completeMatch 是否完全匹配 * @return array|false */ - private function match(string $url, array $option, array $pattern, bool $completeMatch) + private function checkMatch(string $url, array $option, array $pattern, bool $completeMatch) { if (isset($option['complete_match'])) { $completeMatch = $option['complete_match']; diff --git a/vendor/topthink/think-orm/src/db/Fetch.php b/vendor/topthink/think-orm/src/db/Fetch.php index 16caed2b0..a997a859f 100644 --- a/vendor/topthink/think-orm/src/db/Fetch.php +++ b/vendor/topthink/think-orm/src/db/Fetch.php @@ -421,10 +421,8 @@ class Fetch if (!empty($options['group'])) { // 支持GROUP - $bind = $this->query->getBind(); - $subSql = $this->query->options($options)->field('count(' . $field . ') AS think_count')->bind($bind)->buildSql(); - - $query = $this->query->newQuery()->table([$subSql => '_group_count_']); + $subSql = $this->query->field('count(' . $field . ') AS think_count')->buildSql(); + $query = $this->query->newQuery()->table([$subSql => '_group_count_']); return $query->fetchsql()->aggregate('COUNT', '*'); } else { diff --git a/vendor/topthink/think-orm/src/db/builder/Sqlite.php b/vendor/topthink/think-orm/src/db/builder/Sqlite.php index 78a307d28..ff17c5d6c 100644 --- a/vendor/topthink/think-orm/src/db/builder/Sqlite.php +++ b/vendor/topthink/think-orm/src/db/builder/Sqlite.php @@ -24,8 +24,8 @@ class Sqlite extends Builder /** * limit * @access public - * @param Query $query 查询对象 - * @param mixed $limit + * @param Query $query 查询对象 + * @param mixed $limit * @return string */ public function parseLimit(Query $query, string $limit): string @@ -47,7 +47,7 @@ class Sqlite extends Builder /** * 随机排序 * @access protected - * @param Query $query 查询对象 + * @param Query $query 查询对象 * @return string */ protected function parseRand(Query $query): string @@ -58,9 +58,9 @@ class Sqlite extends Builder /** * 字段和表名处理 * @access public - * @param Query $query 查询对象 - * @param mixed $key 字段名 - * @param bool $strict 严格检测 + * @param Query $query 查询对象 + * @param mixed $key 字段名 + * @param bool $strict 严格检测 * @return string */ public function parseKey(Query $query, $key, bool $strict = false): string @@ -73,7 +73,7 @@ class Sqlite extends Builder $key = trim($key); - if (strpos($key, '.')) { + if (strpos($key, '.') && !preg_match('/[,\'\"\(\)`\s]/', $key)) { [$table, $key] = explode('.', $key, 2); $alias = $query->getOptions('alias'); @@ -88,8 +88,12 @@ class Sqlite extends Builder } } + if ('*' != $key && !preg_match('/[,\'\"\*\(\)`.\s]/', $key)) { + $key = '`' . $key . '`'; + } + if (isset($table)) { - $key = $table . '.' . $key; + $key = '`' . $table . '`.' . $key; } return $key; @@ -98,8 +102,8 @@ class Sqlite extends Builder /** * 设置锁机制 * @access protected - * @param Query $query 查询对象 - * @param bool|string $lock + * @param Query $query 查询对象 + * @param bool|string $lock * @return string */ protected function parseLock(Query $query, $lock = false): string diff --git a/vendor/topthink/think-orm/src/db/connector/Sqlite.php b/vendor/topthink/think-orm/src/db/connector/Sqlite.php index c664f202d..3e42a9092 100644 --- a/vendor/topthink/think-orm/src/db/connector/Sqlite.php +++ b/vendor/topthink/think-orm/src/db/connector/Sqlite.php @@ -42,7 +42,7 @@ class Sqlite extends PDOConnection public function getFields(string $tableName): array { [$tableName] = explode(' ', $tableName); - $sql = 'PRAGMA table_info( ' . $tableName . ' )'; + $sql = 'PRAGMA table_info( \'' . $tableName . '\' )'; $pdo = $this->getPDOStatement($sql); $result = $pdo->fetchAll(PDO::FETCH_ASSOC); diff --git a/vendor/topthink/think-orm/src/model/concern/Attribute.php b/vendor/topthink/think-orm/src/model/concern/Attribute.php index 9201f903c..e4aa07b4b 100644 --- a/vendor/topthink/think-orm/src/model/concern/Attribute.php +++ b/vendor/topthink/think-orm/src/model/concern/Attribute.php @@ -382,6 +382,9 @@ trait Attribute } elseif (isset($this->type[$name])) { // 类型转换 $value = $this->writeTransform($value, $this->type[$name]); + } elseif (is_object($value) && method_exists($value, '__toString')) { + // 对象类型 + $value = $value->__toString(); } // 设置数据对象属性 diff --git a/vendor/topthink/think-orm/src/model/relation/BelongsTo.php b/vendor/topthink/think-orm/src/model/relation/BelongsTo.php index 941e1d44c..0802b11ae 100644 --- a/vendor/topthink/think-orm/src/model/relation/BelongsTo.php +++ b/vendor/topthink/think-orm/src/model/relation/BelongsTo.php @@ -236,12 +236,11 @@ class BelongsTo extends OneToOne $relationModel->exists(true); } + // 设置关联属性 + $result->setRelation($relation, $relationModel); if (!empty($this->bindAttr)) { // 绑定关联属性 $this->bindAttr($result, $relationModel); - } else { - // 设置关联属性 - $result->setRelation($relation, $relationModel); } } } @@ -277,12 +276,12 @@ class BelongsTo extends OneToOne $relationModel->exists(true); } + // 设置关联属性 + $result->setRelation($relation, $relationModel); + if (!empty($this->bindAttr)) { // 绑定关联属性 $this->bindAttr($result, $relationModel); - } else { - // 设置关联属性 - $result->setRelation($relation, $relationModel); } } diff --git a/vendor/topthink/think-orm/src/model/relation/BelongsToMany.php b/vendor/topthink/think-orm/src/model/relation/BelongsToMany.php index 75eab1e2a..98909068c 100644 --- a/vendor/topthink/think-orm/src/model/relation/BelongsToMany.php +++ b/vendor/topthink/think-orm/src/model/relation/BelongsToMany.php @@ -137,6 +137,30 @@ class BelongsToMany extends Relation ->setParent(clone $this->parent); } + /** + * 组装Pivot模型 + * @access public + * @param Model $result 模型对象 + * @return array + */ + protected function matchPivot(Model $result): array + { + $pivot = []; + foreach ($result->getData() as $key => $val) { + if (strpos($key, '__')) { + [$name, $attr] = explode('__', $key, 2); + + if ('pivot' == $name) { + $pivot[$attr] = $val; + unset($result->$key); + } + } + } + + $result->setRelation($this->pivotDataName, $this->newPivot($pivot)); + return $pivot; + } + /** * 根据关联条件查询当前模型 * @access public @@ -326,24 +350,13 @@ class BelongsToMany extends Relation // 组装模型数据 $data = []; foreach ($list as $set) { - $pivot = []; - foreach ($set->getData() as $key => $val) { - if (strpos($key, '__')) { - [$name, $attr] = explode('__', $key, 2); - if ('pivot' == $name) { - $pivot[$attr] = $val; - unset($set->$key); - } - } - } - $key = $pivot[$this->localKey]; + $pivot = $this->matchPivot($set); + $key = $pivot[$this->localKey]; if ($this->withLimit && isset($data[$key]) && count($data[$key]) >= $this->withLimit) { continue; } - $set->setRelation($this->pivotDataName, $this->newPivot($pivot)); - $data[$key][] = $set; } @@ -594,21 +607,8 @@ class BelongsToMany extends Relation $foreignKey = $this->foreignKey; $localKey = $this->localKey; - $this->query->getModel()->filter(function ($result, $options) { - $pivot = []; - - foreach ($result->getData() as $key => $val) { - if (strpos($key, '__')) { - [$name, $attr] = explode('__', $key, 2); - - if ('pivot' == $name) { - $pivot[$attr] = $val; - unset($result->$key); - } - } - } - - $result->setRelation($this->pivotDataName, $this->newPivot($pivot)); + $this->query->filter(function ($result, $options) { + $this->matchPivot($result); }); // 关联查询 diff --git a/vendor/topthink/think-orm/src/model/relation/HasManyThrough.php b/vendor/topthink/think-orm/src/model/relation/HasManyThrough.php index d4b7d9127..fc620264b 100644 --- a/vendor/topthink/think-orm/src/model/relation/HasManyThrough.php +++ b/vendor/topthink/think-orm/src/model/relation/HasManyThrough.php @@ -258,8 +258,14 @@ class HasManyThrough extends Relation $closure($this->getClosureType($closure)); } + $throughKey = $this->throughKey; + + if ($this->baseQuery) { + $throughKey = Str::snake(class_basename($this->model)) . "." . $this->throughKey; + } + $list = $this->query - ->where($this->throughKey, 'in', $keys) + ->where($throughKey, 'in', $keys) ->cache($cache[0] ?? false, $cache[1] ?? null, $cache[2] ?? null) ->select(); diff --git a/vendor/topthink/think-orm/src/model/relation/HasOne.php b/vendor/topthink/think-orm/src/model/relation/HasOne.php index be4927b61..269f0d7f2 100644 --- a/vendor/topthink/think-orm/src/model/relation/HasOne.php +++ b/vendor/topthink/think-orm/src/model/relation/HasOne.php @@ -234,13 +234,12 @@ class HasOne extends OneToOne $relationModel->setParent(clone $result); $relationModel->exists(true); } + // 设置关联属性 + $result->setRelation($relation, $relationModel); if (!empty($this->bindAttr)) { // 绑定关联属性 $this->bindAttr($result, $relationModel); - } else { - // 设置关联属性 - $result->setRelation($relation, $relationModel); } } } @@ -276,11 +275,12 @@ class HasOne extends OneToOne $relationModel->exists(true); } + // 设置关联属性 + $result->setRelation($relation, $relationModel); + if (!empty($this->bindAttr)) { // 绑定关联属性 $this->bindAttr($result, $relationModel); - } else { - $result->setRelation($relation, $relationModel); } } -- GitLab