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