Skip to content

Create a transaction save point for multiple commits #1192

Discussion options

You must be logged in to vote

After much research, I found a way to go about it, please let me know if there are any issues with my process.

so, rather than having to start a new session and commit each change, I instead flush to get the id I need to perform the following action. So instead of what I have above, I have this.


from app.extensions import db
from app.models import User, Wallet, Profile

def create_user(data):
    # create user
    user = User(**data)
    db.session.add(user)
    db.session.flush()

    # create user profile
    profile = Profile(user_id=user.id)
    db.session.add(wallet)
    db.session.flush()

    # create user wallet
    wallet = Walletprofile_id=profile.id)
    db.session.add(wallet)…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by idenyigabriel
Comment options

You must be logged in to vote
0 replies
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