Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializing a model with a relationship always results in a list of ids. How to expand to a nested object? #428

Open
nosachamos opened this issue Feb 20, 2022 · 0 comments

Comments

@nosachamos
Copy link

nosachamos commented Feb 20, 2022

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant