From: Eevee Date: Mon, 14 Mar 2011 06:43:08 +0000 (-0700) Subject: Tidy up relation creation for name tables. X-Git-Tag: veekun-promotions/2011041101~33^2~15 X-Git-Url: http://git.veekun.com/zzz-pokedex.git/commitdiff_plain/3a8097b37302ff0c1fa922407cf7bcfd853a1989?hp=d397f4856007d95c442f54ca0d70a50d31ced21e Tidy up relation creation for name tables. --- diff --git a/pokedex/db/tables.py b/pokedex/db/tables.py index 6c18177..6e23ebf 100644 --- a/pokedex/db/tables.py +++ b/pokedex/db/tables.py @@ -1884,24 +1884,22 @@ def makeTextTable(object_table, name_plural, name_singular, columns, lazy): ) mapper(Strings, table, - properties={ - "object_id": synonym(safe_name + '_id'), - "language": relation( - Language, - primaryjoin=table.c.language_id == Language.id, - ), - }, - ) + properties={ + "object_id": synonym(safe_name + '_id'), + "language": relation(Language, + primaryjoin=table.c.language_id == Language.id, + ), + safe_name: relation(object_table, + primaryjoin=(object_table.id == table.c[safe_name + "_id"]), + backref=backref(name_plural, + collection_class=attribute_mapped_collection('language'), + lazy=lazy, + ), + ), + }, + ) # The relation to the object - setattr(object_table, name_plural, relation( - Strings, - primaryjoin=(object_table.id == Strings.object_id), - backref=safe_name, - collection_class=attribute_mapped_collection('language'), - lazy=lazy, - )) - str(getattr(object_table, name_plural)) # [MORE MAGIC]. aka do not remove, or entire app fails. XXX what the fuck man Strings.object = getattr(Strings, safe_name) # Link the tables themselves, so we can get them if needed