Re: [SQLObject] Optional One to One Relationships
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: David W. <da...@su...> - 2004-06-18 11:12:25
|
Clifford, >> How would you represent an optional one to one relationship with >> SQLObject? A use case would be a system where there is a table for >> person and another for donor. A person can be a donor but need not be >> a donor. If a person becomes a donor, there must not be more than one >> donor row. Donations are handled in another table. > > > Answering my own question, one way of dealing with this is to make the > foreign key in the dependent table unique. e.g. > > create table donor ( > id serial primary key, > person_id integer unique reference person(id), > ... > > Now to figure out how to capture and decode the errors raised by > PostgreSQL. I would use the same primary key as used in the person table as both primary key and foreign key. That neatly enforces that you cannot have 2 donors for one person. Regards Dave -- David Warnock, Sundayta Ltd. http://www.sundayta.com iDocSys for Document Management. VisibleResults for Fundraising. Development and Hosting of Web Applications and Sites. |