Skip to content
Advertisement

Flask-SQLAlchemy Legacy vs New Query Interface

I am trying to update some queries in a web application because as stated in Flask-SQLAlchemy

JavaScript

I have a query:

JavaScript

Which is translated into:

JavaScript

And I take the subnets variable and loop it over in my view in two different locations. And it works.

However, when I try to update my query and use the new SQLAlchemy interface:

JavaScript

I can only loop once and there is nothing left to loop over in the second loop?

How can I achieve the same result with the new query interface?

Advertisement

Answer

As noted in the comments to the question, your second example is not directly comparable to your first example because your second example is missing the .all() at the end.

Side note:

JavaScript

is a convenient shorthand for

JavaScript

and is the recommended approach for SQLAlchemy 1.4+.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement