Gets a single row from the db matching the criteria set by args/kwargs. Behaves like :meth:`get` but returns ``None`` instead of raising ``NoMatch`` when no row matches. ``MultipleMatches`` is still raised when criteria are provided and more than one row matches.
(self, *args: Any, **kwargs: Any)
| 1121 | return None |
| 1122 | |
| 1123 | async def get_or_none(self, *args: Any, **kwargs: Any) -> Optional["T"]: |
| 1124 | """ |
| 1125 | Gets a single row from the db matching the criteria set by args/kwargs. |
| 1126 | |
| 1127 | Behaves like :meth:`get` but returns ``None`` instead of raising |
| 1128 | ``NoMatch`` when no row matches. ``MultipleMatches`` is still raised |
| 1129 | when criteria are provided and more than one row matches. |
| 1130 | |
| 1131 | :raises MultipleMatches: when criteria are set (via ``filter``/``exclude`` |
| 1132 | or args/kwargs) and more than one row matches them. |
| 1133 | :param kwargs: fields names and proper value types |
| 1134 | :type kwargs: Any |
| 1135 | :return: returned model or None |
| 1136 | :rtype: Optional[Model] |
| 1137 | """ |
| 1138 | try: |
| 1139 | return await self.get(*args, **kwargs) |
| 1140 | except ormar.NoMatch: |
| 1141 | return None |
| 1142 | |
| 1143 | async def get(self, *args: Any, **kwargs: Any) -> "T": # noqa: CCR001 |
| 1144 | """ |