fix sqlalchemy many to x relationship loading
This commit is contained in:
@@ -26,7 +26,7 @@ async def reprocess(ep_items: Evepraisal, ep_mat: Evepraisal, efficiency: float
|
||||
|
||||
item_reprocess: List[PriceReprocess] = []
|
||||
for rawitem in ep_items.items:
|
||||
# item = sde.exec(select(models_sde.Type).where(models_sde.Type.id == rawitem.typeID)).one()
|
||||
# item = sde.exec(select(models_sde.Type).where(models_sde.SDEType.id == rawitem.typeID)).one()
|
||||
item = db.get(models_sde.SDEType, rawitem.typeID)
|
||||
buy_reprocess = sell_reprocess = 0.0
|
||||
for mat in item.materials.all():
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
from typing import Optional, List
|
||||
from sqlmodel import SQLModel, Field, Relationship
|
||||
from functools import partial
|
||||
|
||||
DynamicRelationship = partial(Relationship, sa_relationship_kwargs={"lazy": "dynamic"}) # change default lazy loading to dynamic
|
||||
|
||||
|
||||
class SDEIcon(SQLModel, table=True):
|
||||
@@ -8,10 +11,10 @@ class SDEIcon(SQLModel, table=True):
|
||||
description: Optional[str] = None
|
||||
iconFile: str
|
||||
|
||||
categories: List['SDECategory'] = Relationship(back_populates="icon")
|
||||
groups: List['SDEGroup'] = Relationship(back_populates="icon")
|
||||
marketgroups: List['SDEMarketGroup'] = Relationship(back_populates="icon")
|
||||
types: List['SDEType'] = Relationship(back_populates="icon")
|
||||
categories: List['SDECategory'] = DynamicRelationship(back_populates="icon")
|
||||
groups: List['SDEGroup'] = DynamicRelationship(back_populates="icon")
|
||||
marketgroups: List['SDEMarketGroup'] = DynamicRelationship(back_populates="icon")
|
||||
types: List['SDEType'] = DynamicRelationship(back_populates="icon")
|
||||
|
||||
|
||||
class SDECategory(SQLModel, table=True):
|
||||
@@ -23,7 +26,7 @@ class SDECategory(SQLModel, table=True):
|
||||
name: str
|
||||
published: bool
|
||||
|
||||
groups: List['SDEGroup'] = Relationship(back_populates="category")
|
||||
groups: List['SDEGroup'] = DynamicRelationship(back_populates="category")
|
||||
|
||||
|
||||
class SDEGroup(SQLModel, table=True):
|
||||
@@ -44,7 +47,7 @@ class SDEGroup(SQLModel, table=True):
|
||||
published: bool
|
||||
useBasePrice: bool
|
||||
|
||||
types: List['SDEType'] = Relationship(back_populates="group")
|
||||
types: List['SDEType'] = DynamicRelationship(back_populates="group")
|
||||
|
||||
|
||||
class SDEMarketGroup(SQLModel, table=True):
|
||||
@@ -61,9 +64,9 @@ class SDEMarketGroup(SQLModel, table=True):
|
||||
parent_marketgroup_id: Optional[int] = Field(default=None, foreign_key="sdemarketgroup.id")
|
||||
parent_marketgroup: Optional['SDEMarketGroup'] = Relationship(back_populates="children_marketgroups",
|
||||
sa_relationship_kwargs={"remote_side": 'SDEMarketGroup.id'}) # workaround for self reference: https://github.com/tiangolo/sqlmodel/issues/127#issuecomment-1224135123
|
||||
children_marketgroups: List['SDEMarketGroup'] = Relationship(back_populates="parent_marketgroup")
|
||||
children_marketgroups: List['SDEMarketGroup'] = DynamicRelationship(back_populates="parent_marketgroup")
|
||||
|
||||
types: List['SDEType'] = Relationship(back_populates="marketgroup")
|
||||
types: List['SDEType'] = DynamicRelationship(back_populates="marketgroup")
|
||||
|
||||
|
||||
class SDEType(SQLModel, table=True):
|
||||
@@ -86,10 +89,10 @@ class SDEType(SQLModel, table=True):
|
||||
volume: Optional[float] = None
|
||||
portionSize: int
|
||||
|
||||
materials: List['SDETypeMaterial'] = Relationship(back_populates="type",
|
||||
sa_relationship_kwargs={"foreign_keys": '[SDETypeMaterial.type_id]'}) # https://github.com/tiangolo/sqlmodel/issues/10#issuecomment-1537445078
|
||||
material_of: List['SDETypeMaterial'] = Relationship(back_populates="material_type",
|
||||
sa_relationship_kwargs={"foreign_keys": '[SDETypeMaterial.material_type_id]'}) # https://github.com/tiangolo/sqlmodel/issues/10#issuecomment-1537445078
|
||||
materials: List['SDETypeMaterial'] = DynamicRelationship(back_populates="type",
|
||||
sa_relationship_kwargs={"lazy": "dynamic", "foreign_keys": '[SDETypeMaterial.type_id]'}) # https://github.com/tiangolo/sqlmodel/issues/10#issuecomment-1537445078
|
||||
material_of: List['SDETypeMaterial'] = DynamicRelationship(back_populates="material_type",
|
||||
sa_relationship_kwargs={"lazy": "dynamic", "foreign_keys": '[SDETypeMaterial.material_type_id]'}) # https://github.com/tiangolo/sqlmodel/issues/10#issuecomment-1537445078
|
||||
|
||||
|
||||
class SDETypeMaterial(SQLModel, table=True):
|
||||
|
||||
Reference in New Issue
Block a user