Skip to content

Neither view template nor form element (add, edit) are handling hasOne relations #219

@xavier83ar

Description

@xavier83ar

It seems that the view template it trying to show them the same way as belongsTo relation, which is ok, but it ignores it when filtering with map function. BelongsTo and hasOne relations are mixed together into $immediateAssociations array, then this array is filtered checking if the foreingKey exists as a field, which is true for belongsTo associations but not for hasOne:

$immediateAssociations = $associations['BelongsTo'] + $associations['HasOne'];
// ...
$associationFields = collection($fields)
    ->map(function($field) use ($immediateAssociations) {
        foreach ($immediateAssociations as $alias => $details) {
            if ($field === $details['foreignKey']) {
                return [$field => $details];
            }
        }
    })
    ->filter()
    ->reduce(function($fields, $value) {
        return $fields + $value;
    }, []);

As for the form template, used on add and edit, there is no clue of hasOne relations. Is it on purpose?

In the meantime I'm working to see if I can fix view template.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions