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

Relationship exclude to serializate #85

Open
jeandelacruz opened this issue May 3, 2022 · 2 comments
Open

Relationship exclude to serializate #85

jeandelacruz opened this issue May 3, 2022 · 2 comments

Comments

@jeandelacruz
Copy link

jeandelacruz commented May 3, 2022

I have run into the problem that, exclude to field relation, it does not do so.

First Model

class User(BaseModel):
    id = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(String(100), index=True)
    shopping_carts = relationship(
        'ShoppingCart', uselist=True, back_populates='user'
    )

Second Model

class ShoppingCart(BaseModel):
    id = Column(Integer, primary_key=True, autoincrement=True)
    user_id = Column(Integer, ForeignKey('users.id'))
    user = relationship(
        'User', uselist=False, back_populates='shopping_carts'
    )

Use smart query.

@michaelbukachi
Copy link
Collaborator

@jeandelacruz Do you mind adding an example of the query you are running, what's being returned, and what's expected to be returned?

@jeandelacruz
Copy link
Author

@jeandelacruz Do you mind adding an example of the query you are running, what's being returned, and what's expected to be returned?

This code:

records = self.model.smart_query(
            filters={**filters},
            sort_attrs=['id'],
            schema={
                'role': JOINED,
                'shopping_carts': JOINED
            }
        ).paginate(
            per_page=query.per_page, page=query.page
        )

return jsonify(results=records.to_dict(nested=True, exclude=['shopping_carts']))

Results:
download

Expected returned:
download

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

2 participants