Yan
Yan

Reputation: 1444

how to make get() query with entity in ponyorm

I'm using ponyorm. How can I convert this query into one that returns only one result if it exists? I want it to throw an error if there is more than one result, similar to the entity.get() query.

url = 'some url'
access= select(c for c in Access if c.people_url.lower().startswith(url))

Thank you.

Upvotes: 1

Views: 146

Answers (1)

Alexander Kozlovsky
Alexander Kozlovsky

Reputation: 4849

You can use get method of a query:

url = 'some url'
query = select(c for c in Access if c.people_url.lower().startswith(url))
obj = query.get()

This method throws MultipleObjectsFoundError if more than one object was found

Upvotes: 1

Related Questions