marshmallow-sqlalchemy
marshmallow-sqlalchemy copied to clipboard
Serializing a model with a relationship always results in a list of ids. How to expand to a nested object?
An example can be found on the main doc page (https://marshmallow-sqlalchemy.readthedocs.io/en/latest/)
author = Author(name="Chuck Paluhniuk")
author_schema = AuthorSchema()
book = Book(title="Fight Club", author=author)
session.add(author)
session.add(book)
session.commit()
dump_data = author_schema.dump(author)
print(dump_data)
# {'id': 1, 'name': 'Chuck Paluhniuk', 'books': [1]}
Note that books comes out as a list, and only the book id is in the list.
I'd like to expand one of these relationships when serializing, so that the entire book object appears in the list instead.
Can this be done with marshmallow-sqlalchemy? I can't seem to find a way.
Thank you!