On Tue, Jun 3, 2008 at 2:49 PM, Etienne Robillard
<[EMAIL PROTECTED]> wrote:

> I agree with you, and think this should be better expressed. Perhaps without
> words which refers to abstract C++ concepts like pointers, and using a 
> vocabulary
> more adapted to Python. At least this would be more helpful for understanding 
> whats going
> on there.

Sorry that what I am trying to say is not clear.  I suppose that I am
too close to it.  Let's suppose the simplest example possible:

class Place(models.Model):
    # primary key here is called "id"
    pass
class Restaurant(Place):
    # primary key here is called "place_ptr_id"
    pass

Now suppose I do this:

    >>> r = Restaurant(pk=1)

This does NOT set r.id = 1.  My first question is, should it?

Second, suppose there already is a place with id=1, and I do the above.

    >>> p = Place.objects.create(pk=1)
    >>> r = Restaurant(pk=1)
    >>> # modify r ...
    >>> r.save()

Maybe I've done something wrong already here, it's possible this
already isn't supported.  But this statement will do an UPDATE into
the restaurant table, and an INSERT into the place table.  At the end,
we have

    >>> r.pk
    2
    >>> r.id
    2

This may be trying to do something that isn't supported, but
nonetheless getting a totally new key cannot be right.  I think that r
was in an inconsistant state, a state that Django does not support.
Specifically, before we save,

    >>> r._get_pk_val( Place._meta)  # returns None
    >>> r._get_pk_val( Restaurant._meta)
    1

The point I was trying to make in the original message is that this is
already weird, on 2 counts.  First, logically an object only has one
primary key.  It doesn't depend on anything except the object.  If
you're asking for the key into a different table, then that's a
foreign key.

Second, if r.id and r.pk are different, then you have two different
objects! The database rows do not point to each other, and so an
attempt to save the object to the database should not succeed.

I can see two possible ways to fix this, one is to raise an exception
when you try to save the inconsistent objects.  The other is to set
all database primary key columns (primary for this object, not
counting foreign keys) when the object's primary key is set.  I'm
trying to ask which is the right fix.

Elizabeth

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to