Patches item #1353728, was opened at 2005-11-11 08:20
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Pau Aliagas (linux4u)
Assigned to: Nobody/Anonymous (nobody)
Summary: define foreign keys in Style
Initial Comment:
I don't like to use attrID all along the code to access related tables, I want to be able use the nomeclature I like taking advantage of the nice Style idea. This is especially true when you create RelatedJoins when you use a nomeclature like I do (table.id_table), but it's the same for all the nomeclatures you can imagine.
In styles.py it warns:
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"
With this patch you can define how you want the foreign keys generated, they won't be mandatorily generated as attrID.
Example:
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]
class mm_server(SQLObject):
class sqlmeta:
table = "smsarena.mm_server"
style = LongStyle(longID = True)
_connection = conn_smsarena
server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server")
tz = StringCol(length = 20, default = 'CET', notNone = True)
conutry_code = StringCol(length = 2, varchar = False, default = '', notNone = True)
# until now I had to do this
# mm_server_aliases = SQLMultipleJoin("mm_server_alias", joinColumn = "mm_serverID", orderBy = "server")
# now it's perfect!
mm_server_aliases = SQLMultipleJoin("mm_server_alias", orderBy = "server")
class mm_server_alias(SQLObject):
class sqlmeta:
table = "smsarena.mm_server_alias"
style = LongStyle(longID = True)
_connection = conn_smsarena
# until now I had to do this
# mm_server = ForeignKey("mm_server", dbName = "id_mm_server")
mm_server = ForeignKey("mm_server")
server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server")
I hope it's clear :)
Pau
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338
|