TTT
TTT

Reputation: 6895

An SQLAlchemy analogue to Rails' Model#find

In Rails I'm used to calling Model.find(id) to fetch a record from a database.

Now in SQLAlchemy I'm using db_session.query(Model).filter(Model.id == id). Does SQLAlchemy have something similar as Rails' find method?

Upvotes: 0

Views: 60

Answers (1)

tuomur
tuomur

Reputation: 7088

Assuming you mean a primary key, there is Query.get() in the API:

db_session.query(Model).get(id)

Upvotes: 4

Related Questions