def serialize(self, schema, data, **kwargs) -> typing.MutableMapping:
"""Composes the final relationships object."""
document = OrderedDict()
if data is None:
document['data'] = data
elif isinstance(data, Mapping):
# JSON API resource linkage or JSON API relationships object
if 'type' in data and 'id' in data:
document['data'] = data
else:
# the related resource instance
document['data'] = \
schema.ctx.registry.ensure_identifier(data, asdict=True)
links = kwargs.get('links')
if links is not None:
document['links'] = links
return document
评论列表
文章目录