Added ISO-3166 country codes to languages table and lookup.
[zzz-pokedex.git] / pokedex / db / tables.py
1 # encoding: utf8
2
3 from sqlalchemy import Column, ForeignKey, MetaData, Table
4 from sqlalchemy.ext.declarative import declarative_base
5 from sqlalchemy.ext.associationproxy import association_proxy
6 from sqlalchemy.orm import backref, relation
7 from sqlalchemy.types import *
8 from sqlalchemy.databases.mysql import *
9
10 from pokedex.db import rst
11
12 metadata = MetaData()
13 TableBase = declarative_base(metadata=metadata)
14
15 class Ability(TableBase):
16 __tablename__ = 'abilities'
17 __singlename__ = 'ability'
18 id = Column(Integer, primary_key=True, nullable=False)
19 name = Column(Unicode(24), nullable=False)
20 flavor_text = Column(Unicode(64), nullable=False)
21 effect = Column(Unicode(255), nullable=False)
22
23 class ContestCombo(TableBase):
24 __tablename__ = 'contest_combos'
25 first_move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False, autoincrement=False)
26 second_move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False, autoincrement=False)
27
28 class ContestEffect(TableBase):
29 __tablename__ = 'contest_effects'
30 id = Column(Integer, primary_key=True, nullable=False)
31 appeal = Column(SmallInteger, nullable=False)
32 jam = Column(SmallInteger, nullable=False)
33 flavor_text = Column(Unicode(64), nullable=False)
34 effect = Column(Unicode(255), nullable=False)
35
36 class EggGroup(TableBase):
37 __tablename__ = 'egg_groups'
38 id = Column(Integer, primary_key=True, nullable=False)
39 name = Column(Unicode(16), nullable=False)
40
41 class Encounter(TableBase):
42 """Rows in this table represent encounters with wild Pokémon.
43
44 Within a given area in a given game, encounters are differentiated by the
45 slot they are in and a world condition.
46
47 Groups of slots belong to encounter types; these are what the player is
48 doing to get an encounter, such as surfing or walking through tall grass.
49
50 Within an encounter type, slots are defined primarily by rarity. Each slot
51 can also be affected by a world condition; for example, the 20% slot for
52 walking in tall grass is affected by whether a swarm is in effect in the
53 areas. "There is a swarm" and "there is not a swarm" are conditions, and
54 together they make a condition group. However, since "not a swarm" is a
55 base state rather than any sort of new state, it is omitted and instead
56 referred to by a NULL.
57
58 A slot (20% walking in grass) and single world condition (NULL, i.e. no
59 swarm) are thus enough to define a specific encounter.
60
61 Well, okay, almost: each slot actually appears twice.
62 """
63
64 __tablename__ = 'encounters'
65 id = Column(Integer, primary_key=True, nullable=False)
66 version_id = Column(Integer, ForeignKey('versions.id'), nullable=False, autoincrement=False)
67 location_area_id = Column(Integer, ForeignKey('location_areas.id'), nullable=False, autoincrement=False)
68 encounter_type_slot_id = Column(Integer, ForeignKey('encounter_type_slots.id'), nullable=False, autoincrement=False)
69 encounter_condition_id = Column(Integer, ForeignKey('encounter_conditions.id'), nullable=True, autoincrement=False)
70 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), nullable=False, autoincrement=False)
71 min_level = Column(Integer, nullable=False, autoincrement=False)
72 max_level = Column(Integer, nullable=False, autoincrement=False)
73
74 class EncounterCondition(TableBase):
75 """Rows in this table represent something different about the world that
76 can affect what Pokémon are encountered.
77 """
78
79 __tablename__ = 'encounter_conditions'
80 id = Column(Integer, primary_key=True, nullable=False)
81 encounter_condition_group_id = Column(Integer, ForeignKey('encounter_condition_groups.id'), primary_key=False, nullable=False, autoincrement=False)
82 name = Column(Unicode(64), nullable=False)
83
84 class EncounterConditionGroup(TableBase):
85 """Rows in this table represent a group of mutually exclusive conditions,
86 such as morning/day/night. "Conditions" that are part of the default state
87 of the world, such as "not during a swarm" or "not using the PokéRadar",
88 are not included in this table and are referred to by NULLs in other
89 tables.
90 """
91
92 __tablename__ = 'encounter_condition_groups'
93 id = Column(Integer, primary_key=True, nullable=False)
94 name = Column(Unicode(64), nullable=False)
95
96 class EncounterType(TableBase):
97 """Rows in this table represent ways the player can enter a wild encounter;
98 i.e. surfing, fishing, or walking through tall grass.
99 """
100
101 __tablename__ = 'encounter_types'
102 id = Column(Integer, primary_key=True, nullable=False)
103 name = Column(Unicode(64), nullable=False)
104
105 class EncounterTypeSlot(TableBase):
106 """Rows in this table represent an abstract "slot" within an encounter
107 type, associated with both a condition group and a rarity.
108
109 Note that there are two encounters per slot, so the rarities will only add
110 up to 50.
111 """
112
113 __tablename__ = 'encounter_type_slots'
114 id = Column(Integer, primary_key=True, nullable=False)
115 encounter_type_id = Column(Integer, ForeignKey('encounter_types.id'), primary_key=False, nullable=False, autoincrement=False)
116 encounter_condition_group_id = Column(Integer, ForeignKey('encounter_condition_groups.id'), primary_key=False, nullable=True, autoincrement=False)
117 rarity = Column(Integer, nullable=False, autoincrement=False)
118
119 class EvolutionChain(TableBase):
120 __tablename__ = 'evolution_chains'
121 id = Column(Integer, primary_key=True, nullable=False)
122 growth_rate_id = Column(Integer, ForeignKey('growth_rates.id'), nullable=False)
123 steps_to_hatch = Column(Integer, nullable=False)
124 baby_trigger_item = Column(Unicode(12))
125
126 class EvolutionMethod(TableBase):
127 __tablename__ = 'evolution_methods'
128 id = Column(Integer, primary_key=True, nullable=False)
129 name = Column(Unicode(64), nullable=False)
130 description = Column(Unicode(255), nullable=False)
131
132 class Generation(TableBase):
133 __tablename__ = 'generations'
134 id = Column(Integer, primary_key=True, nullable=False)
135 name = Column(Unicode(16), nullable=False)
136 main_region = Column(Unicode(16), nullable=False)
137
138 class GrowthRate(TableBase):
139 """`formula` is written in LaTeX math notation."""
140 __tablename__ = 'growth_rates'
141 id = Column(Integer, primary_key=True, nullable=False)
142 name = Column(Unicode(20), nullable=False)
143 formula = Column(Unicode(500), nullable=False)
144
145 class Item(TableBase):
146 __tablename__ = 'items'
147 __singlename__ = 'item'
148 id = Column(Integer, primary_key=True, nullable=False)
149 name = Column(Unicode(16), nullable=False)
150
151 class Language(TableBase):
152 __tablename__ = 'languages'
153 id = Column(Integer, primary_key=True, nullable=False)
154 iso3166 = Column(Unicode(2), nullable=False)
155 name = Column(Unicode(16), nullable=False)
156
157 class Location(TableBase):
158 __tablename__ = 'locations'
159 __singlename__ = 'location'
160 id = Column(Integer, primary_key=True, nullable=False)
161 generation_id = Column(Integer, ForeignKey('generations.id'), nullable=False)
162 name = Column(Unicode(64), nullable=False)
163
164 class LocationArea(TableBase):
165 __tablename__ = 'location_areas'
166 id = Column(Integer, primary_key=True, nullable=False)
167 location_id = Column(Integer, ForeignKey('locations.id'), nullable=False)
168 internal_id = Column(Integer, nullable=False)
169 name = Column(Unicode(64), nullable=True)
170
171 class LocationAreaEncounterRate(TableBase):
172 __tablename__ = 'location_area_encounter_rates'
173 location_area_id = Column(Integer, ForeignKey('location_areas.id'), primary_key=True, nullable=False, autoincrement=False)
174 encounter_type_id = Column(Integer, ForeignKey('encounter_types.id'), primary_key=True, nullable=False, autoincrement=False)
175 rate = Column(Integer, nullable=True)
176
177 class Machine(TableBase):
178 __tablename__ = 'machines'
179 machine_number = Column(Integer, primary_key=True, nullable=False, autoincrement=False)
180 version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, nullable=False, autoincrement=False)
181 move_id = Column(Integer, ForeignKey('moves.id'), nullable=False)
182
183 class MoveEffectCategory(TableBase):
184 __tablename__ = 'move_effect_categories'
185 id = Column(Integer, primary_key=True, nullable=False)
186 name = Column(Unicode(64), nullable=False)
187 can_affect_user = Column(Boolean, nullable=False)
188
189 class MoveEffectCategoryMap(TableBase):
190 __tablename__ = 'move_effect_category_map'
191 move_effect_id = Column(Integer, ForeignKey('move_effects.id'), primary_key=True, nullable=False)
192 move_effect_category_id = Column(Integer, ForeignKey('move_effect_categories.id'), primary_key=True, nullable=False)
193 affects_user = Column(Boolean, primary_key=True, nullable=False)
194
195 class MoveDamageClass(TableBase):
196 __tablename__ = 'move_damage_classes'
197 id = Column(Integer, primary_key=True, nullable=False)
198 name = Column(Unicode(8), nullable=False)
199 description = Column(Unicode(64), nullable=False)
200
201 class MoveEffect(TableBase):
202 __tablename__ = 'move_effects'
203 id = Column(Integer, primary_key=True, nullable=False)
204 priority = Column(SmallInteger, nullable=False)
205 short_effect = Column(Unicode(256), nullable=False)
206 effect = Column(Unicode(5120), nullable=False)
207
208 class MoveFlag(TableBase):
209 __tablename__ = 'move_flags'
210 move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False, autoincrement=False)
211 move_flag_type_id = Column(Integer, ForeignKey('move_flag_types.id'), primary_key=True, nullable=False, autoincrement=False)
212
213 class MoveFlagType(TableBase):
214 __tablename__ = 'move_flag_types'
215 id = Column(Integer, primary_key=True, nullable=False)
216 name = Column(Unicode(32), nullable=False)
217 description = Column(rst.RstTextColumn(128), nullable=False)
218
219 class MoveFlavorText(TableBase):
220 __tablename__ = 'move_flavor_text'
221 move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False, autoincrement=False)
222 generation_id = Column(Integer, ForeignKey('generations.id'), primary_key=True, nullable=False, autoincrement=False)
223 flavor_text = Column(Unicode(255), nullable=False)
224
225 class MoveName(TableBase):
226 __tablename__ = 'move_names'
227 move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False, autoincrement=False)
228 language_id = Column(Integer, ForeignKey('languages.id'), primary_key=True, nullable=False, autoincrement=False)
229 name = Column(Unicode(16), nullable=False)
230
231 class MoveTarget(TableBase):
232 __tablename__ = 'move_targets'
233 id = Column(Integer, primary_key=True, nullable=False)
234 name = Column(Unicode(32), nullable=False)
235 description = Column(Unicode(128), nullable=False)
236
237 class Move(TableBase):
238 __tablename__ = 'moves'
239 __singlename__ = 'move'
240 id = Column(Integer, primary_key=True, nullable=False)
241 name = Column(Unicode(12), nullable=False)
242 generation_id = Column(Integer, ForeignKey('generations.id'), nullable=False)
243 type_id = Column(Integer, ForeignKey('types.id'), nullable=False)
244 power = Column(SmallInteger)
245 pp = Column(SmallInteger, nullable=False)
246 accuracy = Column(SmallInteger)
247 target_id = Column(Integer, ForeignKey('move_targets.id'), nullable=False)
248 damage_class_id = Column(Integer, ForeignKey('move_damage_classes.id'), nullable=False)
249 effect_id = Column(Integer, ForeignKey('move_effects.id'), nullable=False)
250 effect_chance = Column(Integer)
251 contest_type = Column(Unicode(8), nullable=False)
252 contest_effect_id = Column(Integer, ForeignKey('contest_effects.id'), nullable=True)
253 super_contest_effect_id = Column(Integer, ForeignKey('super_contest_effects.id'), nullable=False)
254
255 class Pokemon(TableBase):
256 """The core to this whole mess.
257
258 Note that I use both 'forme' and 'form' in both code and the database. I
259 only use 'forme' when specifically referring to Pokémon that have multiple
260 distinct species as forms—i.e., different stats or movesets. 'Form' is a
261 more general term referring to any variation within a species, including
262 purely cosmetic forms like Unown.
263 """
264 __tablename__ = 'pokemon'
265 __singlename__ = 'pokemon'
266 id = Column(Integer, primary_key=True, nullable=False)
267 name = Column(Unicode(20), nullable=False)
268 forme_name = Column(Unicode(16))
269 forme_base_pokemon_id = Column(Integer, ForeignKey('pokemon.id'))
270 generation_id = Column(Integer, ForeignKey('generations.id'))
271 evolution_chain_id = Column(Integer, ForeignKey('evolution_chains.id'))
272 evolution_parent_pokemon_id = Column(Integer, ForeignKey('pokemon.id'))
273 evolution_method_id = Column(Integer, ForeignKey('evolution_methods.id'))
274 evolution_parameter = Column(Unicode(32))
275 height = Column(Integer, nullable=False)
276 weight = Column(Integer, nullable=False)
277 species = Column(Unicode(16), nullable=False)
278 color = Column(Unicode(6), nullable=False)
279 pokemon_shape_id = Column(Integer, ForeignKey('pokemon_shapes.id'), nullable=False)
280 habitat = Column(Unicode(16), nullable=False)
281 gender_rate = Column(Integer, nullable=False)
282 capture_rate = Column(Integer, nullable=False)
283 base_experience = Column(Integer, nullable=False)
284 base_happiness = Column(Integer, nullable=False)
285 gen1_internal_id = Column(Integer)
286 is_baby = Column(Boolean, nullable=False)
287 has_gen4_fem_sprite = Column(Boolean, nullable=False)
288 has_gen4_fem_back_sprite = Column(Boolean, nullable=False)
289
290 ### Stuff to handle alternate Pokémon forms
291
292 @property
293 def national_id(self):
294 """Returns the National Pokédex number for this Pokémon. Use this
295 instead of the id directly; alternate formes may make the id incorrect.
296 """
297
298 if self.forme_base_pokemon_id:
299 return self.forme_base_pokemon_id
300 return self.id
301
302 @property
303 def full_name(self):
304 """Returns the name of this Pokémon, including its Forme, if any."""
305
306 if self.forme_name:
307 return "%s %s" % (self.forme_name.capitalize(), self.name)
308 return self.name
309
310 @property
311 def normal_form(self):
312 """Returns the normal form for this Pokémon; i.e., this will return
313 regular Deoxys when called on any Deoxys form.
314 """
315
316 if self.forme_base_pokemon:
317 return self.forme_base_pokemon
318
319 return self
320
321 class PokemonAbility(TableBase):
322 __tablename__ = 'pokemon_abilities'
323 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False)
324 ability_id = Column(Integer, ForeignKey('abilities.id'), nullable=False)
325 slot = Column(Integer, primary_key=True, nullable=False, autoincrement=False)
326
327 class PokemonDexNumber(TableBase):
328 __tablename__ = 'pokemon_dex_numbers'
329 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False)
330 generation_id = Column(Integer, ForeignKey('generations.id'), primary_key=True, nullable=False, autoincrement=False)
331 pokedex_number = Column(Integer, nullable=False)
332
333 class PokemonEggGroup(TableBase):
334 __tablename__ = 'pokemon_egg_groups'
335 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False)
336 egg_group_id = Column(Integer, ForeignKey('egg_groups.id'), primary_key=True, nullable=False, autoincrement=False)
337
338 class PokemonFlavorText(TableBase):
339 __tablename__ = 'pokemon_flavor_text'
340 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False)
341 version_id = Column(Integer, ForeignKey('versions.id'), primary_key=True, nullable=False, autoincrement=False)
342 flavor_text = Column(Unicode(255), nullable=False)
343
344 class PokemonFormGroup(TableBase):
345 __tablename__ = 'pokemon_form_groups'
346 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False)
347 description = Column(Unicode(512), nullable=False)
348
349 class PokemonFormSprite(TableBase):
350 __tablename__ = 'pokemon_form_sprites'
351 id = Column(Integer, primary_key=True, nullable=False)
352 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False)
353 introduced_in_version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, nullable=False, autoincrement=False)
354 name = Column(Unicode(16), nullable=True)
355
356 class PokemonItem(TableBase):
357 __tablename__ = 'pokemon_items'
358 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False)
359 version_id = Column(Integer, ForeignKey('versions.id'), primary_key=True, nullable=False, autoincrement=False)
360 item_id = Column(Integer, ForeignKey('items.id'), primary_key=True, nullable=False, autoincrement=False)
361 rarity = Column(Integer, nullable=False)
362
363 class PokemonMove(TableBase):
364 __tablename__ = 'pokemon_moves'
365 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False)
366 version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, nullable=False, autoincrement=False)
367 move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False, autoincrement=False, index=True)
368 pokemon_move_method_id = Column(Integer, ForeignKey('pokemon_move_methods.id'), primary_key=True, nullable=False, autoincrement=False)
369 level = Column(Integer, primary_key=True, nullable=True, autoincrement=False)
370 order = Column(Integer, nullable=True)
371
372 class PokemonMoveMethod(TableBase):
373 __tablename__ = 'pokemon_move_methods'
374 id = Column(Integer, primary_key=True, nullable=False, autoincrement=False)
375 name = Column(Unicode(64), nullable=False)
376 description = Column(Unicode(255), nullable=False)
377
378 class PokemonName(TableBase):
379 __tablename__ = 'pokemon_names'
380 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False)
381 language_id = Column(Integer, ForeignKey('languages.id'), primary_key=True, nullable=False, autoincrement=False)
382 name = Column(Unicode(16), nullable=False)
383
384 class PokemonShape(TableBase):
385 __tablename__ = 'pokemon_shapes'
386 id = Column(Integer, primary_key=True, nullable=False)
387 name = Column(Unicode(24), nullable=False)
388 awesome_name = Column(Unicode(16), nullable=False)
389
390 class PokemonStat(TableBase):
391 __tablename__ = 'pokemon_stats'
392 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False)
393 stat_id = Column(Integer, ForeignKey('stats.id'), primary_key=True, nullable=False, autoincrement=False)
394 base_stat = Column(Integer, nullable=False)
395 effort = Column(Integer, nullable=False)
396
397 class PokemonType(TableBase):
398 __tablename__ = 'pokemon_types'
399 pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False)
400 type_id = Column(Integer, ForeignKey('types.id'), nullable=False)
401 slot = Column(Integer, primary_key=True, nullable=False, autoincrement=False)
402
403 class Stat(TableBase):
404 __tablename__ = 'stats'
405 id = Column(Integer, primary_key=True, nullable=False)
406 name = Column(Unicode(16), nullable=False)
407
408 class SuperContestCombo(TableBase):
409 __tablename__ = 'super_contest_combos'
410 first_move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False, autoincrement=False)
411 second_move_id = Column(Integer, ForeignKey('moves.id'), primary_key=True, nullable=False, autoincrement=False)
412
413 class SuperContestEffect(TableBase):
414 __tablename__ = 'super_contest_effects'
415 id = Column(Integer, primary_key=True, nullable=False)
416 appeal = Column(SmallInteger, nullable=False)
417 flavor_text = Column(Unicode(64), nullable=False)
418
419 class TypeEfficacy(TableBase):
420 __tablename__ = 'type_efficacy'
421 damage_type_id = Column(Integer, ForeignKey('types.id'), primary_key=True, nullable=False, autoincrement=False)
422 target_type_id = Column(Integer, ForeignKey('types.id'), primary_key=True, nullable=False, autoincrement=False)
423 damage_factor = Column(Integer, nullable=False)
424
425 class Type(TableBase):
426 __tablename__ = 'types'
427 __singlename__ = 'type'
428 id = Column(Integer, primary_key=True, nullable=False)
429 name = Column(Unicode(8), nullable=False)
430 abbreviation = Column(Unicode(3), nullable=False)
431
432 class VersionGroup(TableBase):
433 __tablename__ = 'version_groups'
434 id = Column(Integer, primary_key=True, nullable=False)
435 generation_id = Column(Integer, ForeignKey('generations.id'), nullable=False)
436
437 class Version(TableBase):
438 __tablename__ = 'versions'
439 id = Column(Integer, primary_key=True, nullable=False)
440 version_group_id = Column(Integer, ForeignKey('version_groups.id'), nullable=False)
441 name = Column(Unicode(32), nullable=False)
442
443
444 ### Relations down here, to avoid ordering problems
445 ContestCombo.first = relation(Move, primaryjoin=ContestCombo.first_move_id==Move.id,
446 backref='contest_combo_first')
447 ContestCombo.second = relation(Move, primaryjoin=ContestCombo.second_move_id==Move.id,
448 backref='contest_combo_second')
449
450 Encounter.pokemon = relation(Pokemon, backref='encounters')
451 Encounter.version = relation(Version, backref='encounters')
452 Encounter.location_area = relation(LocationArea, backref='encounters')
453 Encounter.slot = relation(EncounterTypeSlot, backref='encounters')
454 Encounter.condition = relation(EncounterCondition, backref='encounters')
455
456 EncounterCondition.group = relation(EncounterConditionGroup,
457 backref='conditions')
458
459 EncounterTypeSlot.type = relation(EncounterType, backref='slots')
460
461 EvolutionChain.growth_rate = relation(GrowthRate, backref='evolution_chains')
462
463 Generation.versions = relation(Version, secondary=VersionGroup.__table__)
464
465 LocationArea.location = relation(Location, backref='areas')
466
467 Machine.version_group = relation(VersionGroup)
468
469 Move.contest_effect = relation(ContestEffect, backref='moves')
470 Move.contest_combo_next = association_proxy('contest_combo_first', 'second')
471 Move.contest_combo_prev = association_proxy('contest_combo_second', 'first')
472 Move.damage_class = relation(MoveDamageClass, backref='moves')
473 Move.flags = association_proxy('move_flags', 'flag')
474 Move.flavor_text = relation(MoveFlavorText, order_by=MoveFlavorText.generation_id, backref='move')
475 Move.foreign_names = relation(MoveName, backref='pokemon')
476 Move.generation = relation(Generation, backref='moves')
477 Move.machines = relation(Machine, backref='move')
478 Move.move_effect = relation(MoveEffect, backref='moves')
479 Move.move_flags = relation(MoveFlag, backref='move')
480 Move.super_contest_effect = relation(SuperContestEffect, backref='moves')
481 Move.super_contest_combo_next = association_proxy('super_contest_combo_first', 'second')
482 Move.super_contest_combo_prev = association_proxy('super_contest_combo_second', 'first')
483 Move.target = relation(MoveTarget, backref='moves')
484 Move.type = relation(Type, backref='moves')
485
486 Move.effect = rst.MoveEffectProperty('effect')
487 Move.priority = association_proxy('move_effect', 'priority')
488 Move.short_effect = rst.MoveEffectProperty('short_effect')
489
490 MoveEffect.category_map = relation(MoveEffectCategoryMap)
491 MoveEffect.categories = association_proxy('category_map', 'category')
492 MoveEffectCategoryMap.category = relation(MoveEffectCategory)
493
494 MoveFlag.flag = relation(MoveFlagType)
495
496 MoveFlavorText.generation = relation(Generation)
497
498 MoveName.language = relation(Language)
499
500 Pokemon.abilities = relation(Ability, secondary=PokemonAbility.__table__,
501 order_by=PokemonAbility.slot,
502 backref='pokemon')
503 Pokemon.formes = relation(Pokemon, primaryjoin=Pokemon.id==Pokemon.forme_base_pokemon_id,
504 backref=backref('forme_base_pokemon',
505 remote_side=[Pokemon.id]))
506 Pokemon.dex_numbers = relation(PokemonDexNumber, backref='pokemon')
507 Pokemon.egg_groups = relation(EggGroup, secondary=PokemonEggGroup.__table__,
508 order_by=PokemonEggGroup.egg_group_id,
509 backref='pokemon')
510 Pokemon.evolution_chain = relation(EvolutionChain, backref='pokemon')
511 Pokemon.evolution_method = relation(EvolutionMethod)
512 Pokemon.evolution_children = relation(Pokemon, primaryjoin=Pokemon.id==Pokemon.evolution_parent_pokemon_id,
513 backref=backref('evolution_parent',
514 remote_side=[Pokemon.id]))
515 Pokemon.flavor_text = relation(PokemonFlavorText, order_by=PokemonFlavorText.pokemon_id, backref='pokemon')
516 Pokemon.foreign_names = relation(PokemonName, backref='pokemon')
517 Pokemon.items = relation(PokemonItem)
518 Pokemon.generation = relation(Generation, backref='pokemon')
519 Pokemon.shape = relation(PokemonShape, backref='pokemon')
520 Pokemon.stats = relation(PokemonStat, backref='pokemon')
521 Pokemon.types = relation(Type, secondary=PokemonType.__table__)
522
523 PokemonDexNumber.generation = relation(Generation)
524
525 PokemonFlavorText.version = relation(Version)
526
527 PokemonItem.item = relation(Item, backref='pokemon')
528 PokemonItem.version = relation(Version)
529
530 PokemonFormGroup.pokemon = relation(Pokemon, backref=backref('form_group',
531 uselist=False))
532 PokemonFormSprite.pokemon = relation(Pokemon, backref='form_sprites')
533 PokemonFormSprite.introduced_in = relation(VersionGroup)
534
535 PokemonMove.pokemon = relation(Pokemon, backref='pokemon_moves')
536 PokemonMove.version_group = relation(VersionGroup)
537 PokemonMove.move = relation(Move, backref='pokemon_moves')
538 PokemonMove.method = relation(PokemonMoveMethod)
539
540 PokemonName.language = relation(Language)
541
542 PokemonStat.stat = relation(Stat)
543
544 SuperContestCombo.first = relation(Move, primaryjoin=SuperContestCombo.first_move_id==Move.id,
545 backref='super_contest_combo_first')
546 SuperContestCombo.second = relation(Move, primaryjoin=SuperContestCombo.second_move_id==Move.id,
547 backref='super_contest_combo_second')
548
549 Type.damage_efficacies = relation(TypeEfficacy,
550 primaryjoin=Type.id
551 ==TypeEfficacy.damage_type_id,
552 backref='damage_type')
553 Type.target_efficacies = relation(TypeEfficacy,
554 primaryjoin=Type.id
555 ==TypeEfficacy.target_type_id,
556 backref='target_type')
557
558 Version.version_group = relation(VersionGroup, backref='versions')
559 Version.generation = association_proxy('version_group', 'generation')
560
561 VersionGroup.generation = relation(Generation, backref='version_groups')