Return at most one result or raise an exception. Returns ``None`` if the query selects no rows. Raises ``sqlalchemy.orm.exc.MultipleResultsFound`` if multiple object identities are returned, or if multiple rows are returned for a query that returns only scalar value
(self)
| 2766 | return self.limit(1)._iter().first() # type: ignore |
| 2767 | |
| 2768 | def one_or_none(self) -> Optional[_T]: |
| 2769 | """Return at most one result or raise an exception. |
| 2770 | |
| 2771 | Returns ``None`` if the query selects |
| 2772 | no rows. Raises ``sqlalchemy.orm.exc.MultipleResultsFound`` |
| 2773 | if multiple object identities are returned, or if multiple |
| 2774 | rows are returned for a query that returns only scalar values |
| 2775 | as opposed to full identity-mapped entities. |
| 2776 | |
| 2777 | Calling :meth:`_query.Query.one_or_none` |
| 2778 | results in an execution of the |
| 2779 | underlying query. |
| 2780 | |
| 2781 | .. seealso:: |
| 2782 | |
| 2783 | :meth:`_query.Query.first` |
| 2784 | |
| 2785 | :meth:`_query.Query.one` |
| 2786 | |
| 2787 | :meth:`_engine.Result.one_or_none` - v2 comparable method. |
| 2788 | |
| 2789 | :meth:`_engine.Result.scalar_one_or_none` - v2 comparable method. |
| 2790 | |
| 2791 | """ |
| 2792 | return self._iter().one_or_none() # type: ignore |
| 2793 | |
| 2794 | def one(self) -> _T: |
| 2795 | """Return exactly one result or raise an exception. |