Skip to content

Question about nested objects and .save_related() #314

Answered by collerek
franzwollang asked this question in Q&A
Discussion options

You must be logged in to vote

You don't provide a full code sample but I would assume you provide a primary keys for your deeply nested relations.

Save related is a shortcut function that executes upsert on each model. The insert/update operation is based on the presence of the primary keys. If the primary key is present ormar assumes it's an update (otherwise you would get an integrity error with duplicated primary key if in fact the given models already exists and you try to insert them again).

So if you want to create the full tree at once (so all models are not existing) the child models cannot have primary keys set (so should be autoincrement or columns with default). I can add something like force_insert flag bu…

Replies: 2 comments 13 replies

Comment options

You must be logged in to vote
4 replies
@franzwollang
Comment options

@franzwollang
Comment options

@collerek
Comment options

@franzwollang
Comment options

Answer selected by franzwollang
Comment options

You must be logged in to vote
9 replies
@franzwollang
Comment options

@collerek
Comment options

@franzwollang
Comment options

@franzwollang
Comment options

@collerek
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants