Browse Source

Fixed `yii\db\ActiveRelationTrait::populateRelation()` fails when `link` refers to string convertable object attribute, like `\MongoId`

tags/2.0.4
Klimov Paul 10 years ago
parent
commit
c0fc4596e2
  1. 1
      framework/CHANGELOG.md
  2. 21
      framework/db/ActiveRelationTrait.php

1
framework/CHANGELOG.md

@ -31,6 +31,7 @@ Yii Framework 2 Change Log
- Bug #8082: Fixed `yii\db\BaseActiveRecord::getAttributeLabel()` return wrong label for related attribute, if several relations in chain share same name (klimov-paul)
- Bug #8149: Fixed `yii\db\BaseActiveRecord::updateCounters()` fails for new record saved with counter attribute not set (klimov-paul)
- Bug #8158: Avoid exception when detecting console screen size fails on windows (EliasZ)
- Bug #8165: Fixed `yii\db\ActiveRelationTrait::populateRelation()` fails when `link` refers to string convertable object attribute, like `\MongoId` (klimov-paul)
- Enh #1468: Added ability to specify hints for model attributes via `attributeHints()` method (klimov-paul)
- Enh #3376: Added `yii\validators\EachValidator`, which allows validation of the array attributes (klimov-paul)
- Enh #6442: Improved error message on `FileHelper::createDirectory()` to include the path name of the directory (cebe)

21
framework/db/ActiveRelationTrait.php

@ -483,19 +483,20 @@ trait ActiveRelationTrait
*/
private function getModelKey($model, $attributes)
{
if (count($attributes) > 1) {
$key = [];
foreach ($attributes as $attribute) {
$key[] = $model[$attribute];
$key = [];
foreach ($attributes as $attribute) {
$value = $model[$attribute];
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();
}
$key[] = $value;
}
if (count($key) > 1) {
return serialize($key);
} else {
$attribute = reset($attributes);
$key = $model[$attribute];
return is_scalar($key) ? $key : serialize($key);
}
$key = reset($key);
return is_scalar($key) ? $key : serialize($key);
}
/**

Loading…
Cancel
Save