Author: ianb
Date: 2004-08-30 13:07:02 -0400 (Mon, 30 Aug 2004)
New Revision: 208
Modified:
trunk/SQLObject/sqlobject/col.py
Log:
Use FOREIGN KEY constraints even if cascade isn't explicitly given
Modified: trunk/SQLObject/sqlobject/col.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/col.py 2004-08-30 17:01:33 UTC (rev 207)
+++ trunk/SQLObject/sqlobject/col.py 2004-08-30 17:07:02 UTC (rev 208)
@@ -446,20 +446,25 @@
def postgresCreateSQL(self):
from main import findClass
sql =3D SOKeyCol.postgresCreateSQL(self)
+ other =3D findClass(self.foreignKey)
+ tName =3D other._table
+ idName =3D other._idName
if self.cascade is not None:
- other =3D findClass(self.foreignKey)
- tName =3D other._table
- idName =3D other._idName
- action =3D self.cascade and 'CASCADE' or 'RESTRICT'
- constraint =3D ('CONSTRAINT %(tName)s_exists '
- 'FOREIGN KEY(%(colName)s) '
- 'REFERENCES %(tName)s(%(idName)s) '
- 'ON DELETE %(action)s' %
- {'tName':tName,
- 'colName':self.dbName,
- 'idName':idName,
- 'action':action})
- sql =3D ', '.join([sql, constraint])
+ if self.cascade:
+ action =3D 'ON DELETE CASCADE'
+ else:
+ action =3D 'ON DELETE RESTRICT'
+ else:
+ action =3D ''
+ constraint =3D ('CONSTRAINT %(tName)s_exists '
+ 'FOREIGN KEY (%(colName)s) '
+ 'REFERENCES %(tName)s (%(idName)s) '
+ '%(action)s' %
+ {'tName': tName,
+ 'colName': self.dbName,
+ 'idName': idName,
+ 'action': action})
+ sql =3D ', '.join([sql, constraint])
return sql
=20
def sybaseCreateSQL(self):
|