【问题标题】:Requesting list of embedded objects请求嵌入对象列表
【发布时间】:2015-02-22 18:07:34
【问题描述】:

我有包含嵌入图像列表的项目端点。方案如下:

_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',
            }
        },
    }
}

所以我正在尝试向项目端点发出请求以获取嵌入式对象

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

但我收到的不是嵌入图像,而是带有图像_ids 列表的常规对象。

这是一个对象的例子:

{
    "_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"
}

我尝试将列表中的图像 ID 转换为对象 ID,但没有帮助。任何想法为什么它不起作用?谢谢

【问题讨论】:

    标签: eve


    【解决方案1】:

    您的架构定义不正确。定义images 列表时,将scheme 替换为schema

    _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',
                }
            },
        }
    }
    

    然后它将正确嵌入您的图像列表。

    【讨论】:

      猜你喜欢
      • 2021-11-16
      • 1970-01-01
      • 1970-01-01
      • 2020-06-19
      • 1970-01-01
      • 2021-01-16
      • 1970-01-01
      • 2018-09-02
      • 1970-01-01
      相关资源
      最近更新 更多