From 3fbd86982107523c154b0da610b8738b26e0771d Mon Sep 17 00:00:00 2001 From: blitzmann Date: Sun, 3 Jun 2018 16:28:33 -0400 Subject: [PATCH] Get some basic relationships added for mutaplasmids --- eos/db/gamedata/dynamicAttributes.py | 36 ++++++++++++++++++++++------ eos/db/gamedata/item.py | 11 +++++++-- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/eos/db/gamedata/dynamicAttributes.py b/eos/db/gamedata/dynamicAttributes.py index 774f57f78..04d7de2d0 100644 --- a/eos/db/gamedata/dynamicAttributes.py +++ b/eos/db/gamedata/dynamicAttributes.py @@ -18,10 +18,13 @@ # =============================================================================== from sqlalchemy import Column, Float, Integer, Table, ForeignKey -from sqlalchemy.orm import mapper +from sqlalchemy.orm import mapper, relation +from sqlalchemy.ext.associationproxy import association_proxy from eos.db import gamedata_meta -from eos.gamedata import DynamicItem, DynamicItemAttribute, DynamicItemItem +from eos.gamedata import DynamicItem, DynamicItemAttribute, DynamicItemItem, Item + +from eos.gamedata import AttributeInfo dynamic_table = Table("mutaplasmids", gamedata_meta, Column("typeID", ForeignKey("invtypes.typeID"), primary_key=True, index=True), @@ -29,15 +32,34 @@ dynamic_table = Table("mutaplasmids", gamedata_meta, dynamicAttributes_table = Table("mutaplasmidAttributes", gamedata_meta, Column("typeID", Integer, ForeignKey("mutaplasmids.typeID"), primary_key=True), - Column("attributeID", Integer, primary_key=True), + Column("attributeID", ForeignKey("dgmattribs.attributeID"), primary_key=True), Column("min", Float), Column("max", Float)) dynamicApplicable_table = Table("mutaplasmidItems", gamedata_meta, - Column("typeID", Integer, ForeignKey("mutaplasmids.typeID"), primary_key=True), + Column("typeID", ForeignKey("mutaplasmids.typeID"), primary_key=True), Column("applicableTypeID", ForeignKey("invtypes.typeID"), primary_key=True), ) -mapper(DynamicItem, dynamic_table) -mapper(DynamicItemAttribute, dynamicAttributes_table) -mapper(DynamicItemItem, dynamicApplicable_table) +mapper(DynamicItem, dynamic_table, properties={ + "attributes": relation(DynamicItemAttribute), + "item": relation(Item, foreign_keys=[dynamic_table.c.typeID]), + "resultingItem": relation(Item, foreign_keys=[dynamic_table.c.resultingTypeID]), + }) + +mapper(DynamicItemAttribute, dynamicAttributes_table, + properties={"info": relation(AttributeInfo, lazy=False)}) + +mapper(DynamicItemItem, dynamicApplicable_table, properties={ + "mutaplasmid": relation(DynamicItem), + }) + +DynamicItemAttribute.ID = association_proxy("info", "attributeID") +DynamicItemAttribute.name = association_proxy("info", "attributeName") +DynamicItemAttribute.description = association_proxy("info", "description") +DynamicItemAttribute.published = association_proxy("info", "published") +DynamicItemAttribute.displayName = association_proxy("info", "displayName") +DynamicItemAttribute.highIsGood = association_proxy("info", "highIsGood") +DynamicItemAttribute.iconID = association_proxy("info", "iconID") +DynamicItemAttribute.icon = association_proxy("info", "icon") +DynamicItemAttribute.unit = association_proxy("info", "unit") diff --git a/eos/db/gamedata/item.py b/eos/db/gamedata/item.py index 1760f9157..b32193654 100644 --- a/eos/db/gamedata/item.py +++ b/eos/db/gamedata/item.py @@ -24,7 +24,8 @@ from sqlalchemy.orm.collections import attribute_mapped_collection from eos.db.gamedata.effect import typeeffects_table from eos.db import gamedata_meta -from eos.gamedata import Attribute, Effect, Group, Icon, Item, MetaType, Traits +from eos.gamedata import Attribute, Effect, Group, Icon, Item, MetaType, Traits, DynamicItemItem, DynamicItem +from eos.db.gamedata.dynamicAttributes import dynamicApplicable_table, dynamic_table items_table = Table("invtypes", gamedata_meta, Column("typeID", Integer, primary_key=True), @@ -57,7 +58,13 @@ mapper(Item, items_table, "description" : deferred(items_table.c.description), "traits" : relation(Traits, primaryjoin=traits_table.c.typeID == items_table.c.typeID, - uselist=False) + uselist=False), + "mutaplasmids": relation(DynamicItem, + primaryjoin=dynamicApplicable_table.c.applicableTypeID == items_table.c.typeID, + secondaryjoin=dynamicApplicable_table.c.typeID == DynamicItem.typeID, + secondary=dynamicApplicable_table, + backref="applicableItems" + ) }) Item.category = association_proxy("group", "category")