Browse Source

Fix #18435: Fix ensuring Active Record relation links' keys to be strings

tags/2.0.40
Bizley 4 years ago committed by GitHub
parent
commit
112effc631
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      framework/CHANGELOG.md
  2. 17
      framework/db/ActiveRelationTrait.php

1
framework/CHANGELOG.md

@ -15,6 +15,7 @@ Yii Framework 2 Change Log
- Bug #18287: Fix the OUTPUT got SQL syntax error if the column name is MSSQL keyword e.g key (darkdef)
- Bug #18426: Fix check for route's leading slash in `yii\widgets\Menu` (stevekr)
- Bug #16492: Fix eager loading Active Record relations when relation key is a subject to a type-casting behavior (bizley)
- Bug #18435: Fix ensuring Active Record relation links' keys to be strings (bizley)
2.0.39.3 November 23, 2020

17
framework/db/ActiveRelationTrait.php

@ -585,22 +585,23 @@ trait ActiveRelationTrait
if (count($key) > 1) {
return serialize($key);
}
$key = reset($key);
return is_scalar($key) ? $key : serialize($key);
return reset($key);
}
/**
* @param mixed $value raw key value.
* @param mixed $value raw key value. Since 2.0.40 non-string values must be convertable to string (like special
* objects for cross-DBMS relations, for example: `|MongoId`).
* @return string normalized key value.
*/
private function normalizeModelKey($value)
{
if (is_object($value) && method_exists($value, '__toString')) {
// ensure matching to special objects, which are convertable to string, for cross-DBMS relations, for example: `|MongoId`
$value = $value->__toString();
}
try {
return (string)$value;
} catch (\Exception $e) {
throw new InvalidConfigException('Value must be convertable to string.');
} catch (\Throwable $e) {
throw new InvalidConfigException('Value must be convertable to string.');
}
}
/**

Loading…
Cancel
Save