Skip to content

Embedding only follows _id  #1069

@scholzd

Description

@scholzd

I have the following schemes:

nodes = {
    'type': 'dict',
    'schema': {
        'hardware': {
            'type': 'string',
            'data_relation': {
                'resource': 'nodes_hw',
                'field': 'name',
                'embeddable': True
            }
        }
    }
}

nodes_hw = {
    'type': 'dict',
    'schema': {
        'name': {
            'type': 'string',
            'required': True,
            'unique': True
        }
    }
}

When now querying

/nodes?embedded={"hardware":1}

the resulting value for hardware is null.

The following lines seem to be the problem

eve/eve/methods/common.py

Lines 826 to 829 in cee2f7e

# NOTE: in case it is a DBRef link, the id_field_name is always the _id
# regardless the Eve set-up
id_field_name = "_id" if isinstance(reference, DBRef) \
else config.DOMAIN[subresource]['id_field']

Internally, in nodes_hw a lookup is performed with _id = VALUE_OF_HARDWARE.

Changing this line to use data_relation['field'] yields the expected result.
Then the internal lookup is correctly performed with name = VALUE_OF_HARDWARE
As result, hardware contains a dictionary with the embedded nodes_hw object.

Am I doing something wrong, is this not wanted or is this a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions