#21454: Ignoring certain fields on INSERT and UPDATE queries
-------------------------------------+-------------------------------------
     Reporter:  mpessas              |                    Owner:  mpessas
         Type:  New feature          |                   Status:  assigned
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  oracle               |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by owais):

 == Update ==

 Moved the delegation logic from models closer to the code that generates
 the queries. This makes the implementation a bit more robust as most
 higher level APIs should just work without the need to update anything. It
 also allowed me to add support to querysets for delegation.

 == Field Options ==

 === `delegated=True|False` ===
 A shortcut that automatically sets the the following option to True when
 no value is provided for them.


 === `delegated_on_insert=True|False` ===
 If True, the value of this field will not be skipped from the `INSERT`
 statement completely. This automatically sets `return_on_insert` to `True`
 if not value is given. Supported on all backends.


 === `delegated_on_update=True|False` ===
 If True, the value of this field will not be skipped from the `UPDATE`
 statement completely. This automatically sets `return_on_update` to `True`
 if not value is given. Supported on all backends.


 === `return_on_insert=True|False` ===
 If True, the value for field is loaded and assigned from the database
 along with the `INSERT` statement. Supported on PostgreSQL using the
 `RETURNING` clause and Oracle using the `RETURNING INTO` clause.


 === `return_on_update=True|False` ===
 If True, the value for field is loaded and assigned from the database
 along with the `UPDATE` statement. Supported on PostgreSQL using the
 `RETURNING` clause and Oracle using the `RETURNING INTO` clause.



 == Model API Changes ==

 `save()` method now takes an optional argument called `ignore_delegated`
 which can be a list of delegated field names. This negates the behavior of
 `delegated_on_insert` and `delegated_on_update`.


 == Queryset/Manager API Changes ==

 Querysets have a new method call `ignore_delegated` which takes names of
 delegated fields as arguments and negates the behavior of
 `delegated_on_insert` and `delegated_on_update` for any subsequent
 operations. For example, if we have a delegated field called `created_at`
 on a model, we can temporarily disable delegation to DB for a single
 query.
 {{{
 class MyModel(models.Model):
      pytthon_ts = fields.DatetimeField()
      db_ts = fields.DatetimeField(delegated=True)


 # This will only update python_ts as `db_ts` is delegated to database
 MyModel.objects.update(db_ts=now(), python_ts=now())


 # However, this will update both
 MyModel.objects.ignore_delegated('db_ts').update(db_ts=now(),
 python_on=now())
 }}}

 The above example also applies to `Model.objects.create()`.

--
Ticket URL: <https://code.djangoproject.com/ticket/21454#comment:21>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.67e514e7746e8ca13a8a1907b27328a1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to