22

I've seen a few variations of running a query with SQLAlchemy. For example, here is one version:

posts = db.query(models.Post).filter(models.Post.owner_id==user.id).all() 

What would be the difference between using the above or using .where? Why are there two variations here?

0

1 Answer 1

36

According to the documentation, there is no difference.

method sqlalchemy.orm.Query.where(*criterion)

A synonym for Query.filter().

It was added in version 1.4 by this commit. According to the commit message the reason to add it was to Convert remaining ORM APIs to support 2.0 style.

You can read more about "2.0 style" here.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.