SQLAlchemy: Using delete/update with a join query

Pav Sidhu

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.

socrates

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]

編集
0

コメントを追加

0

関連記事

分類Dev

How to form complex mysql query that has left outer join, aggregate data with group by using SQLAlchemy?

分類Dev

SQL Query Update using a join

分類Dev

insert using sub-query and inner join

分類Dev

Laravel 4.2 Eloquent using lists() with a join query

分類Dev

Create a double join query using Rails Admin

分類Dev

Laravel join query using Laravel eloquent

分類Dev

sqlalchemy query using joinedload exponentially slower with each new filter clause

分類Dev

SQL Server Query Won't Commit Using SQLAlchemy Engine

分類Dev

How to properly join same table multiple times using sqlalchemy core api?

分類Dev

Executing a sqlalchemy exists query

分類Dev

How nested FETCH JOIN works on Hibernate using JpaRepository and @Query annotation?

分類Dev

Join Statement using Query builder with multiple where clause

分類Dev

Using 'OR' inside a LinQ join query (adapting SQL into LinQ)

分類Dev

Executing a query using sum, count, group by and multiple left join MySQL

分類Dev

Android: how to do an inner-join query in sqlite using the ContextResolver?

分類Dev

Eloquent query using join to retrieve pivot table and related data

分類Dev

Get half tree of category : Without using join query in mySql

分類Dev

how left outer join in sqlalchemy?

分類Dev

How to query jsonb array with sqlalchemy

分類Dev

Python & SqlAlchemy - Iterative build of a query

分類Dev

Creating Dynamic Select Query in SqlAlchemy

分類Dev

Convert a complex SQL query to SQLAlchemy

分類Dev

SQLAlchemy include @property in query result?

分類Dev

Convert raw SQL to SQLAlchemy query

分類Dev

instead of fetching multiple tables using pyspark how can we execute join query using jdbc

分類Dev

left join in Linq query

分類Dev

Query in LINQ with self join

分類Dev

Laravel query join on not null

分類Dev

Query is giving cartesian join

Related 関連記事

  1. 1

    How to form complex mysql query that has left outer join, aggregate data with group by using SQLAlchemy?

  2. 2

    SQL Query Update using a join

  3. 3

    insert using sub-query and inner join

  4. 4

    Laravel 4.2 Eloquent using lists() with a join query

  5. 5

    Create a double join query using Rails Admin

  6. 6

    Laravel join query using Laravel eloquent

  7. 7

    sqlalchemy query using joinedload exponentially slower with each new filter clause

  8. 8

    SQL Server Query Won't Commit Using SQLAlchemy Engine

  9. 9

    How to properly join same table multiple times using sqlalchemy core api?

  10. 10

    Executing a sqlalchemy exists query

  11. 11

    How nested FETCH JOIN works on Hibernate using JpaRepository and @Query annotation?

  12. 12

    Join Statement using Query builder with multiple where clause

  13. 13

    Using 'OR' inside a LinQ join query (adapting SQL into LinQ)

  14. 14

    Executing a query using sum, count, group by and multiple left join MySQL

  15. 15

    Android: how to do an inner-join query in sqlite using the ContextResolver?

  16. 16

    Eloquent query using join to retrieve pivot table and related data

  17. 17

    Get half tree of category : Without using join query in mySql

  18. 18

    how left outer join in sqlalchemy?

  19. 19

    How to query jsonb array with sqlalchemy

  20. 20

    Python & SqlAlchemy - Iterative build of a query

  21. 21

    Creating Dynamic Select Query in SqlAlchemy

  22. 22

    Convert a complex SQL query to SQLAlchemy

  23. 23

    SQLAlchemy include @property in query result?

  24. 24

    Convert raw SQL to SQLAlchemy query

  25. 25

    instead of fetching multiple tables using pyspark how can we execute join query using jdbc

  26. 26

    left join in Linq query

  27. 27

    Query in LINQ with self join

  28. 28

    Laravel query join on not null

  29. 29

    Query is giving cartesian join

ホットタグ

アーカイブ