Fixes bug introduced by #2507

The many-to-many relationship types choke pretty hard on this enhancement, so only use it for the simple one-to-many/one-to-one style relations instead.
Fixes #2524
This commit is contained in:
Samuel Georges 2016-12-04 10:48:22 +11:00
parent fad4d52e79
commit afa2c83c3c
1 changed files with 8 additions and 2 deletions

View File

@ -139,9 +139,15 @@ class Relation extends FormWidgetBase
$result = $query->getQuery()->get();
}
// Some simpler relations can specify a custom local or foreign "other" key,
// which can be detected and implemented here automagically.
$primaryKeyName = in_array($relationType, ['hasMany', 'belongsTo', 'hasOne'])
? $relationObject->getOtherKey()
: $relationModel->getKeyName();
$field->options = $usesTree
? $result->listsNested($nameFrom, $relationObject->getOtherKey())
: $result->lists($nameFrom, $relationObject->getOtherKey());
? $result->listsNested($nameFrom, $primaryKeyName)
: $result->lists($nameFrom, $primaryKeyName);
return $field;
});