[SQLObject] foreign keys defined in Style: patch attached
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Pau A. <pa...@sm...> - 2005-11-10 19:11:31
|
On Mon, 7 Nov 2005, Pau Aliagas wrote: A few days ago I wanted to change this... > def instanceAttrToIDAttr(self, attr): > # @@: Right now, because of how names are created for foreign > # keys, you can't really change this style. > return attr + "ID" I attach a patch that does it AFAICT. Now you can define your Style.instanceAttrToIDAttr and all the foreign keys will be defined as you want. There's no more need to hardcode the foreign key as somethingID, you can use the Style you prefer. I.e this is the Style I need, I use id_table as the id of all my tables. # rsplit function for python < 2.4 def rsplit(s, sep, maxsplits=0): """ Like str.rsplit, which is python 2.4+ only. """ l = s.split(sep) if not 0 < maxsplits <= len(l): return l return [sep.join(l[0:-maxsplits])] + l[-maxsplits:] class LongStyle(Style): """ This style is derived from Style, that does not do any translation, but constructs the table ids like id_table. """ def instanceAttrToIDAttr(self, attr): return "id_" + attr def tableReference(self, table): # str.rsplit is python 2.4+ only if version_info >= (2, 4): return "id_" + table.rsplit(".", 1)[-1] else: return "id_" + rsplit(table, ".", 1)[-1] Hope you find it acceptable. -- ____________________________________ Pau Aliagas (((smsARENA smsarena.com Tel. 902010292 ____________________________________ |