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)
| 2823 | return self.limit(1)._iter().first() # type: ignore |
| 2824 | |
| 2825 | def one_or_none(self) -> Optional[_T]: |
| 2826 | """Return at most one result or raise an exception. |
| 2827 | |
| 2828 | Returns ``None`` if the query selects |
| 2829 | no rows. Raises ``sqlalchemy.orm.exc.MultipleResultsFound`` |
| 2830 | if multiple object identities are returned, or if multiple |
| 2831 | rows are returned for a query that returns only scalar values |
| 2832 | as opposed to full identity-mapped entities. |
| 2833 | |
| 2834 | Calling :meth:`_query.Query.one_or_none` |
| 2835 | results in an execution of the |
| 2836 | underlying query. |
| 2837 | |
| 2838 | .. seealso:: |
| 2839 | |
| 2840 | :meth:`_query.Query.first` |
| 2841 | |
| 2842 | :meth:`_query.Query.one` |
| 2843 | |
| 2844 | :meth:`_engine.Result.one_or_none` - v2 comparable method. |
| 2845 | |
| 2846 | :meth:`_engine.Result.scalar_one_or_none` - v2 comparable method. |
| 2847 | |
| 2848 | """ |
| 2849 | return self._iter().one_or_none() # type: ignore |
| 2850 | |
| 2851 | def one(self) -> _T: |
| 2852 | """Return exactly one result or raise an exception. |