Dmitry Tsepelev
Dmitry Tsepelev

Reputation: 115

Requesting list of embedded objects

I have items endpoint which contains a list of embedded images. The scheme looks like:

_schema = {
    'name': required_string,  # group name
    'description': {
        'type': 'string',
        'maxlength': 140,
    },
    'images': {
        'type': 'list',
        'scheme': {
            'type': 'objectid',
            'data_relation': {
                'resource': 'images',
                'embeddable': True,
                'field': '_id',
            }
        },
    }
}

So I'm trying to make a request to the items endpoint to get embedded objects

/items/549ae47f4fb9041305403292?embedded={"images":1}

But instead of embedded images I receive just the regular object with the list of images _ids.

Here is an example of object:

{
    "_updated": "Wed, 24 Dec 2014 16:06:23 GMT",
    "name": "New Item",
    "images": [
        "549ae47f4fb904130540328b",
        "549ae47f4fb904130540328e",
        "549ae47f4fb9041305403291"
    ],
    "_created": "Wed, 24 Dec 2014 16:06:23 GMT",
    "_id": "549ae47f4fb9041305403292",
    "_etag": "949e3b731823bb2c08682ba4b6696b86856ef941",
    "description": "The best item ever"
}

I tried to convert images ids in list to objectids, but it doesn't help. Any ideas why it doesn't work? Thanks

Upvotes: 5

Views: 667

Answers (1)

Nicola Iarocci
Nicola Iarocci

Reputation: 6576

You have an incorrect schema definition. Replace scheme with schema when defining the images list:

_schema = {
    'name': required_string,  # group name
    'description': {
        'type': 'string',
        'maxlength': 140,
    },
    'images': {
        'type': 'list',
        'schema': {                 # this was 'scheme' in your def
            'type': 'objectid',
            'data_relation': {
                'resource': 'images',
                'embeddable': True,
                'field': '_id',
            }
        },
    }
}

It will then properly embed your list of images.

Upvotes: 6

Related Questions