Ticket #2160: 0_pk.2.patch

File 0_pk.2.patch, 1.6 KB (added by Chris Beaven, 17 years ago)

with updated docs

  • django/db/models/base.py

     
    167167
    168168        # First, try an UPDATE. If that doesn't update anything, do an INSERT.
    169169        pk_val = self._get_pk_val()
    170         pk_set = bool(pk_val)
     170        pk_set = bool(pk_val) or pk_val == 0
    171171        record_exists = True
    172172        if pk_set:
    173173            # Determine whether a record with the primary key already exists.
  • docs/db-api.txt

     
    142142or ``UPDATE`` SQL statements. Specifically, when you call ``save()``, Django
    143143follows this algorithm:
    144144
    145     * If the object's primary key attribute is set to a value that evaluates to
    146       ``True`` (i.e., a value other than ``None`` or the empty string), Django
    147       executes a ``SELECT`` query to determine whether a record with the given
    148       primary key already exists.
     145    * If the object's primary key attribute is set to a value that equals ``0``
     146      or evaluates to ``True`` (i.e., a value other than ``None`` or the empty
     147      string), Django executes a ``SELECT`` query to determine whether a record
     148      with the given primary key already exists.
    149149    * If the record with the given primary key does already exist, Django
    150150      executes an ``UPDATE`` query.
    151151    * If the object's primary key attribute is *not* set, or if it's set but a
Back to Top