From 62c8ca421a3ebe4d71c1a37e1c5b812e647707b7 Mon Sep 17 00:00:00 2001 From: Parnassius Date: Sat, 11 Dec 2021 14:34:13 +0100 Subject: [PATCH] Replace a couple of double relationships with a single one with `backref` --- pokedex/db/tables.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/pokedex/db/tables.py b/pokedex/db/tables.py index c37f22d..e2f7a20 100644 --- a/pokedex/db/tables.py +++ b/pokedex/db/tables.py @@ -2475,7 +2475,8 @@ Experience.growth_rate = relationship(GrowthRate, Generation.versions = relationship(Version, secondary=VersionGroup.__table__, innerjoin=True) -Generation.main_region = relationship(Region, innerjoin=True) +Generation.main_region = relationship(Region, innerjoin=True, + backref=backref('generation', uselist=False)) GrowthRate.max_experience_obj = relationship(Experience, @@ -2497,14 +2498,13 @@ Item.flavor_text = relationship(ItemFlavorText, Item.fling_effect = relationship(ItemFlingEffect, backref='items') Item.machines = relationship(Machine, - order_by=Machine.version_group_id.asc()) + order_by=Machine.version_group_id.asc(), + backref='item') Item.category = relationship(ItemCategory, innerjoin=True, backref=backref('items', order_by=Item.identifier.asc())) Item.pocket = association_proxy('category', 'pocket') -ItemCategory.pocket = relationship(ItemPocket, innerjoin=True) - ItemFlavorText.version_group = relationship(VersionGroup, innerjoin=True, lazy='joined') ItemFlavorText.language = relationship(Language, @@ -2518,7 +2518,8 @@ ItemGameIndex.generation = relationship(Generation, ItemPocket.categories = relationship(ItemCategory, innerjoin=True, - order_by=ItemCategory.identifier.asc()) + order_by=ItemCategory.identifier.asc(), + backref=backref('pocket', innerjoin=True)) Location.region = relationship(Region, @@ -2542,11 +2543,6 @@ LocationGameIndex.generation = relationship(Generation, innerjoin=True, lazy='joined') -Machine.item = relationship(Item) -Machine.version_group = relationship(VersionGroup, - innerjoin=True, lazy='joined') - - Move.changelog = relationship(MoveChangelog, order_by=MoveChangelog.changed_in_version_group_id.desc(), backref=backref('move', innerjoin=True, lazy='joined')) @@ -2886,7 +2882,6 @@ PokemonSpecies.conquest_evolution = relationship(ConquestPokemonEvolution, PokemonSpeciesFlavorText.version = relationship(Version, innerjoin=True, lazy='joined') PokemonSpeciesFlavorText.language = relationship(Language, innerjoin=True, lazy='joined') -Region.generation = relationship(Generation, uselist=False) Region.version_group_regions = relationship(VersionGroupRegion, order_by=VersionGroupRegion.version_group_id.asc(), backref='region') @@ -2950,7 +2945,8 @@ VersionGroup.pokemon_move_methods = relationship(PokemonMoveMethod, backref="version_groups") VersionGroup.machines = relationship(Machine, innerjoin=True, - order_by=Machine.machine_number) + order_by=Machine.machine_number, + backref=backref('version_group', innerjoin=True, lazy='joined')) VersionGroupPokemonMoveMethod.version_group = relationship(VersionGroup,