mirror of
https://github.com/django/django.git
synced 2025-07-24 05:36:15 +00:00
Refs #28010 -- Allowed reverse related fields in SELECT FOR UPDATE .. OF.
Thanks Adam Chidlow for polishing the patch.
This commit is contained in:
parent
56b364bacc
commit
03049fb8d9
5 changed files with 61 additions and 6 deletions
|
@ -1628,6 +1628,19 @@ specify the related objects you want to lock in ``select_for_update(of=(...))``
|
|||
using the same fields syntax as :meth:`select_related`. Use the value ``'self'``
|
||||
to refer to the queryset's model.
|
||||
|
||||
You can't use ``select_for_update()`` on nullable relations::
|
||||
|
||||
>>> Person.objects.select_related('hometown').select_for_update()
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
django.db.utils.NotSupportedError: FOR UPDATE cannot be applied to the nullable side of an outer join
|
||||
|
||||
To avoid that restriction, you can exclude null objects if you don't care about
|
||||
them::
|
||||
|
||||
>>> Person.objects.select_related('hometown').select_for_update().exclude(hometown=None)
|
||||
<QuerySet [<Person: ...)>, ...]>
|
||||
|
||||
Currently, the ``postgresql``, ``oracle``, and ``mysql`` database
|
||||
backends support ``select_for_update()``. However, MySQL doesn't support the
|
||||
``nowait``, ``skip_locked``, and ``of`` arguments.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue