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

Issue with association object with primary key composed of two foreign keys #264

Open
eino opened this issue Dec 16, 2019 · 0 comments
Open

Comments

@eino
Copy link

eino commented Dec 16, 2019

Hi,

I have an issue with my data structure. Not sure if it's a bug, or (more probably), something that could be solved by tweaking the shema.

I have two objects, let's call them A and B, and an assotiation object A_to_B with a quantity.
This association object's primary key is composed of the foreign keys of A and B

We receive data as nested : A containing A_to_B containing B :

"a" : {
"id": a_id,
// other A data

b_data: {
quantity: 1,
b: {
"id": b_id,
// B data
}
}

The first time I load the data, everything works fine.
But the issue is that when trying to re-load existing data, sqlalchemy tries to delete the existing A_to_B (and to recreate it afterward).

It seems for some reason, marshmallow-sqlalchemy doesn't realize the association object is the same than the one that exists in the base.
Also at time of merge, sqlalchemy doesn't realize either, and removes the old instance to re-create the same thing.

For now the association schema looks like this :

class AToBSchema(BaseSchema):
    b = Nested(BSchema)
    class Meta(BaseSchema.Meta):
        model = AToB

Any idea to prevent this unnecessary new instance ? (with a deletion of the old one)

@eino eino closed this as completed Dec 16, 2019
@eino eino reopened this Dec 17, 2019
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