[orm-devel] Re: [orm-users] one2one using the primary key as the foriegn key

Diedrich Vorberg dv at t4w.de
Tue Jun 22 15:34:27 CEST 2004


Hi Nigel,

> How do you go about using a one2one mapping in the following situation.
> |--------|   |-----------|
> | Person |   | Picture   |
> ----------   -------------
> | ID     |<->| person_ID |
> | Name   |   | etc       |
> | etc    |   |           |
> |--------|   |-----------|
this is not the setup needed by a one2one relationship. It should look 
like this:

|--------|   |-----------|
| Person |   | Picture   |
----------   -------------
| ID     |   |           |
| ImageId|<->|           |
| Name   |   | etc       |
| etc    |   |           |
|--------|   |-----------|


> Ie, instead of having a separate foreign key in Person, I want its
> primary key to be used. If I try to do this at the moment I can create
> and save person, then I create Picture and as soon as I try to set
> person_id=person it tries to run an UPDATE on the Picture table and that
> crashes the process. 
Setting person.image = image should not alter the image table at all, 
something is going wrong here.

> Alternatively I can insert a Picture, save it
> setting picture.person_id=0, and then set person_id=person. But you
> shouldn't have to insert picture until it is in its final state. Having
> person_id=0 is having the database in an inconsistent state, which is
> bad.
Well, could you post your person and picture classes and a few lines of 
Python code that makes the program go wrong? Also the person and picutre 
SQL definitions would be nice. If you don't want to post them on the 
list you may post them to me privately. Something basic is screwed up 
here, I guess...

Diedrich

-- 
Diedrich Vorberg <diedrich at tux4web.de>      .---.   /             \
http://tux4web.de Tel: 02302 425269        /     \ ((__-^^-,-^^-__))
                                            \.O-O./  `-_---' `---_-'
"Unix is simple, but it takes a genius     /`\_/`\   `--|o` 'o|--'
to understand the simplicity."            //  _  \\     \  `  /
                       - Dennis Ritchie   | \     )|_     ): :(
                                         /`\_`>  <_/ \    :o_o:
      Associate Member of the FSF #1245  \__/'---'\__/     "-"



More information about the orm-devel mailing list