How do you update multiple values in flask-sqlalchemy?
-
21-12-2019 - |
Question
How do you update multiple values?
predictions=Fixture_prediction.query\
.filter_by(user_id=user_id)\
.update(request.form['home_score'],request.form['away_score'])
This is the error I get:
ArgumentError: Valid strategies for session synchronization are False, 'evaluate' and 'fetch'
Solution
You're supposed to use a dictionary with name:value pairs:
query.update({'home_score': request.form['home_score'],
'away_score': request.form['away_score']})
However, keep in mind that this update will bypass all Python based cascading and will not trigger the before_update and after_update events.
OTHER TIPS
So far I haven't seen any examples for a multiple field update. But if it's possible looks like you just need to identify which columns are being updated. Try this...
.update({"column1": request.form['home_score'], "column2" : request.form['away_score']})
Hope this helps!
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow