-Type.damage_efficacies = relation(TypeEfficacy,
- primaryjoin=Type.id
- ==TypeEfficacy.damage_type_id,
- backref='damage_type')
-Type.target_efficacies = relation(TypeEfficacy,
- primaryjoin=Type.id
- ==TypeEfficacy.target_type_id,
- backref='target_type')
-
-Type.generation = relation(Generation, backref='types')
-Type.damage_class = relation(MoveDamageClass, backref='types')
-Type.pokemon = relation(Pokemon, secondary=PokemonType.__table__,
- order_by=Pokemon.order,
- back_populates='types')
-Type.moves = relation(Move, back_populates='type', order_by=Move.id)
-
-Version.version_group = relation(VersionGroup, back_populates='versions')
-Version.generation = association_proxy('version_group', 'generation')
-
-VersionGroup.versions = relation(Version, order_by=Version.id, back_populates='version_group')
-VersionGroup.generation = relation(Generation, backref='version_groups')
-VersionGroup.version_group_regions = relation(VersionGroupRegion, backref='version_group')
-VersionGroup.regions = association_proxy('version_group_regions', 'region')
-VersionGroup.pokedex = relation(Pokedex, back_populates='version_groups')
-
-
-### Add text/prose tables
-
-default_lang = u'en'
-
-def makeTextTable(foreign_table_class, table_suffix_plural, table_suffix_singular, columns, lazy, Language=Language):
- # With "Language", we'd have two language_id. So, rename one to 'lang'
- foreign_key_name = foreign_table_class.__singlename__
- if foreign_key_name == 'language':
- foreign_key_name = 'lang'
-
- table_name = foreign_table_class.__singlename__ + '_' + table_suffix_plural
-
- class TranslatedStringsTable(object):
- __tablename__ = table_name
- _attrname = table_suffix_plural
- _language_identifier = association_proxy('language', 'identifier')
-
- for column_name, column_name_plural, column in columns:
- column.name = column_name
- if not column.nullable:
- # A Python side default value, so that the strings can be set
- # one by one without the DB complaining about missing values
- column.default = ColumnDefault(u'')
-
- table = Table(table_name, foreign_table_class.__table__.metadata,
- Column(foreign_key_name + '_id', Integer, ForeignKey(foreign_table_class.id),
- primary_key=True, nullable=False),
- Column('language_id', Integer, ForeignKey(Language.id),
- primary_key=True, index=True, nullable=False),
- *(column for name, plural, column in columns)
- )
-
- mapper(TranslatedStringsTable, table,
- properties={
- "object_id": synonym(foreign_key_name + '_id'),
- "language": relation(Language,
- primaryjoin=table.c.language_id == Language.id,
- ),
- foreign_key_name: relation(foreign_table_class,
- primaryjoin=(foreign_table_class.id == table.c[foreign_key_name + "_id"]),
- backref=backref(table_suffix_plural,
- collection_class=attribute_mapped_collection('_language_identifier'),
- lazy=lazy,
- ),
- ),
- },
- )