You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 6, 2024. It is now read-only.
If I try to dump a an object with a relationship, then deserialize the output, i do not get the same object - the relationship is now represented as the id of the related schema.
from marshmallow_jsonapi import fields, Schema
from pprint import pprint
class TeamSchema(Schema):
id = fields.Int()
name = fields.Str(required=True)
class Meta:
type_ = 'team'
class AssetSchema(Schema):
id = fields.Int()
name = fields.Str(required=True)
team = fields.Relationship(
include_resource_linkage=True,
type_='team',
schema='TeamSchema',
id_field='id'
)
class Meta:
type_ = 'asset'
data = {'name': 'Asset#1', 'team': {'id': 456}}
print('Input data:')
pprint(data)
asset_serialized = AssetSchema().dump(data)
print('*****DUMP (SERIALIZED) *****')
pprint(asset_serialized)
asset_deserialized = AssetSchema(include_data=('team',)).load(asset_serialized)
print('*****LOAD (DESERIALIZED) *****')
print('Deserialized vs original data:')
pprint(asset_deserialized)
pprint(data)