- 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 name tables
-for table in list(table_classes):
- if issubclass(table, OfficiallyNamed):
- cls = TextColumn
- info=dict(description="The name", format='plaintext', official=True)
- elif issubclass(table, UnofficiallyNamed):
- cls = ProseColumn
- info=dict(description="The name", format='plaintext', official=False)
- else:
- continue
- table.name = cls(Unicode(class_mapper(table).c.identifier.type.length),
- plural='names', index=True, nullable=False, info=info)
-
-### Add text/prose tables
-
-default_lang = u'en'
-
-def makeTextTable(object_table, name_plural, name_singular, columns, lazy):
- # With "Language", we'd have two language_id. So, rename one to 'lang'
- safe_name = object_table.__singlename__
- if safe_name == 'language':
- safe_name = 'lang'
-
- tablename = object_table.__singlename__ + '_' + name_plural
- singlename = object_table.__singlename__ + '_' + name_singular
-
- class Strings(object):
- __tablename__ = tablename
- __singlename__ = singlename
- _attrname = name_plural
- _language_identifier = association_proxy('language', 'identifier')
-
- for name, plural, column in columns:
- column.name = name
-
- table = Table(tablename, metadata,
- Column(safe_name + '_id', Integer, ForeignKey(object_table.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(Strings, table,
- properties={
- "object_id": synonym(safe_name + '_id'),
- "language": relation(
- Language,
- primaryjoin=table.c.language_id == Language.id,
- ),
- },
- )
-
- # 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,
- ))
- Strings.object = getattr(Strings, safe_name)
-
- # Link the tables themselves, so we can get them if needed
- Strings.object_table = object_table
- setattr(object_table, name_singular + '_table', Strings)
-
- for colname, pluralname, column in columns:
- # Provide a property with all the names, and an English accessor
- # for backwards compatibility
- setattr(object_table, pluralname, StringProperty(
- object_table, Strings, colname,
- ))
- setattr(object_table, colname, DefaultLangProperty(pluralname))
-
- if colname == 'name':
- object_table.name_table = Strings
-
- return Strings
-
-class StringProperty(object):
- def __init__(self, cls, stringclass, colname):
- self.cls = cls
- self.colname = colname
- self.stringclass = stringclass
-
- def __get__(self, instance, cls):
- if instance:
- return dict(
- (l, getattr(t, self.colname))
- for l, t
- in getattr(instance, self.stringclass._attrname).items()
- )
- else:
- return self