Using Flask-SQLAlchemy, I would like to delete rows in table Questions
based on the values of another table which is linked to table Topic
which then is linked to table Subject
with foreign keys. I tried this query:
db.session.query(Questions).join(Topic)join(Subject).filter(Subject.account_id==current_user.id).delete()
However, I receive an error:
InvalidRequestError: Can't call Query.update() or Query.delete() when join(), outerjoin(), select_from(), or from_self() has been called
So from this I suppose I cannot use .delete()
with .join()
Is there a workaround for this issue? Thanks.
You don't have to use join for your query, you may done it somehow like
db.session.query(Post).filter(Post.user_id==current_user.id).delete()
Assuming your Post have a user_id column.
Join tables would not know which table to delete, Post or User, because it actually have a convoluted middle table constructed, and query from it.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加