Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cross join in sqlalchemy 1.3

I can't understand how to connect two tables with cross join. Earler, at sqlalchemy version 1.1.4 I do it this way:

A = Table1.sa 
B = Table2.sa
my_query = A.query().join(B, literal(True))

But after updating to version 1.3 it's raise exception:

sqlalchemy.exc.InvalidRequestError: Can't determine which FROM clause to join from, there are multiple FROMS which can join to this entity. Try adding an explicit ON clause to help resolve the ambiguity.

I'm understand that it's mean that I have to do something like that:

my_query = A.query().join(B, A.fireign_key_id = B.id)

But table A haven't foreign key to table B.

How to connect two tables with cross join and without foreign key? Thanks.

like image 963

1 Answers

Thank you for all answers. Exception was raise, because the query couldn't determine which table is left and into query(...) use the fields of table B. After I explicitly indicated the left table, this exception disappeared.

my_query = A.query(...).join(B, A.id != None)
like image 106