Hi,
My abridged schema:
people = Table("people", pg_engine,
Column('key', String, primary_key=True),
Column('firstname', String),
Column('lastname', String),
)
peoplesites = Table("peoplesites", pg_engine,
Column('person', String, ForeignKey("people.key"),
primary_key=True),
Column('site', String),
)
PersonSite.mapper = mapper(PersonSite, peoplesites)
Person.mapper = mapper(Person, people,
properties = {
'Sites' : relation(PersonSite.mapper, uselist=True,
primaryjoin=(peoplesites.c.person==people.c.key)),
},
)
I think that's enough to show my problem. Anyway, I have a method in
the Person class called addSite() which creates a PersonSite() and
does something like: self.Sites.append(newPersonSite). When I go to
do a commit, however, it seems that the INSERTs come in the wrong
order: the peoplesites insert is done first. This fails, because the
'person' field of the peoplesites table is a foreign key of people.key.
My workaround is to do:
objectsore.commit(newPerson) #Get the person inserted
objectsore.commit() #Get everything else inserted
I know SA is smart about these things, so I'm probably doing
something wrong to cause this. What could be the reason?
--
Dimi Shahbaz, Software Engineer Specialist
California PASS Program
www.cyberhigh.fcoe.k12.ca.us
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users