Commit f210ec82 by Carsten Brandt

Merge pull request #3134 from joaorjose/dev

Typecast model Id so that urls don't break when using MongoDB object Id'...
parents a42b80ec 831be938
...@@ -433,11 +433,19 @@ class Generator extends \yii\gii\Generator ...@@ -433,11 +433,19 @@ class Generator extends \yii\gii\Generator
$class = $this->modelClass; $class = $this->modelClass;
$pks = $class::primaryKey(); $pks = $class::primaryKey();
if (count($pks) === 1) { if (count($pks) === 1) {
return "'id' => \$model->{$pks[0]}"; if (is_subclass_of($class, 'yii\mongodb\ActiveRecord')) {
return "'id' => (string)\$model->{$pks[0]}";
} else {
return "'id' => \$model->{$pks[0]}";
}
} else { } else {
$params = []; $params = [];
foreach ($pks as $pk) { foreach ($pks as $pk) {
$params[] = "'$pk' => \$model->$pk"; if (is_subclass_of($class, 'yii\mongodb\ActiveRecord')) {
$params[] = "'$pk' => (string)\$model->$pk";
} else {
$params[] = "'$pk' => \$model->$pk";
}
} }
return implode(', ', $params); return implode(', ', $params);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment