Migrate from dyn_join_with to selectinload
This commit is contained in:
parent
be8d7c3175
commit
1e3678fb69
5 changed files with 73 additions and 41 deletions
|
@ -76,12 +76,8 @@ class FileImport(Model):
|
||||||
return f'<gisaf.misc.FileImport (gisaf_admin.file_import) {self.path}>'
|
return f'<gisaf.misc.FileImport (gisaf_admin.file_import) {self.path}>'
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def dyn_join_with(cls):
|
def selectinload(cls):
|
||||||
return {
|
return [cls.project, cls.surveyor, cls.equipment]
|
||||||
'project': Project,
|
|
||||||
'surveyor': Surveyor,
|
|
||||||
'equipment': Equipment,
|
|
||||||
}
|
|
||||||
|
|
||||||
def set_import_time(self):
|
def set_import_time(self):
|
||||||
self.time = datetime.now()
|
self.time = datetime.now()
|
||||||
|
|
|
@ -95,13 +95,21 @@ class BaseSurveyModel(BaseModel):
|
||||||
date: date
|
date: date
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def dyn_join_with(cls):
|
def selectinload(cls):
|
||||||
return {
|
return [
|
||||||
'equipment': Equipment,
|
cls.equipment,
|
||||||
'surveyor': Surveyor,
|
cls.surveyor,
|
||||||
'accuracy': Accuracy,
|
cls.accuracy,
|
||||||
'project': Project,
|
cls.project,
|
||||||
}
|
]
|
||||||
|
# @classmethod
|
||||||
|
# def dyn_join_with(cls):
|
||||||
|
# return {
|
||||||
|
# 'equipment': Equipment,
|
||||||
|
# 'surveyor': Surveyor,
|
||||||
|
# 'accuracy': Accuracy,
|
||||||
|
# 'project': Project,
|
||||||
|
# }
|
||||||
|
|
||||||
#async def get_info(self):
|
#async def get_info(self):
|
||||||
# info = await super(BaseSurveyModel, self).get_info()
|
# info = await super(BaseSurveyModel, self).get_info()
|
||||||
|
@ -313,7 +321,7 @@ class GeoModelNoStatus(Model):
|
||||||
get_gdf_with_related: ClassVar[bool] = False
|
get_gdf_with_related: ClassVar[bool] = False
|
||||||
"""
|
"""
|
||||||
get_gdf_with_related indicates that get_df (thus, get_geo_df and the geoJson API for
|
get_gdf_with_related indicates that get_df (thus, get_geo_df and the geoJson API for
|
||||||
the map online) gets related models (1-n relations, as defined with _join_with and dyn_join_with)
|
the map online) gets related models (1-n relations, as defined with selectinload)
|
||||||
by default.
|
by default.
|
||||||
It can be overridden with the with_related parameter when calling get_df.
|
It can be overridden with the with_related parameter when calling get_df.
|
||||||
"""
|
"""
|
||||||
|
@ -371,12 +379,12 @@ class GeoModelNoStatus(Model):
|
||||||
"""
|
"""
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
@classmethod
|
# @classmethod
|
||||||
def get_join_with(cls):
|
# def get_join_with(cls):
|
||||||
if hasattr(cls, 'dyn_join_with'):
|
# if hasattr(cls, 'dyn_join_with'):
|
||||||
return cls.dyn_join_with()
|
# return cls.dyn_join_with()
|
||||||
else:
|
# else:
|
||||||
return cls._join_with
|
# return cls._join_with
|
||||||
|
|
||||||
#@classmethod
|
#@classmethod
|
||||||
#def get_style(cls):
|
#def get_style(cls):
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from sqlmodel import Field, String, JSON, Column
|
from sqlmodel import Field, String, JSON, Relationship
|
||||||
|
|
||||||
from gisaf.models.models_base import Model
|
from gisaf.models.models_base import Model
|
||||||
from gisaf.models.metadata import gisaf_map
|
from gisaf.models.metadata import gisaf_map
|
||||||
|
@ -51,13 +51,21 @@ class BaseMapLayer(Model):
|
||||||
|
|
||||||
id: int | None = Field(primary_key=True, default=None)
|
id: int | None = Field(primary_key=True, default=None)
|
||||||
base_map_id: int = Field(foreign_key='base_map.id', index=True)
|
base_map_id: int = Field(foreign_key='base_map.id', index=True)
|
||||||
|
## Subclasses must include:
|
||||||
|
# base_map: BaseMap = Relationship()
|
||||||
store: str = Field(sa_type=String(100))
|
store: str = Field(sa_type=String(100))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def dyn_join_with(cls):
|
def selectinload(cls):
|
||||||
return {
|
return [
|
||||||
'base_map': BaseMap,
|
cls.base_map
|
||||||
}
|
]
|
||||||
|
|
||||||
|
# @classmethod
|
||||||
|
# def dyn_join_with(cls):
|
||||||
|
# return {
|
||||||
|
# 'base_map': BaseMap,
|
||||||
|
# }
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<models.BaseMapLayer {self.store or '':s}>"
|
return f"<models.BaseMapLayer {self.store or '':s}>"
|
||||||
|
|
|
@ -16,13 +16,23 @@ class RawSurveyModel(BaseSurveyModel, GeoPointMModel):
|
||||||
project_id: int | None = Field(foreign_key='project.id')
|
project_id: int | None = Field(foreign_key='project.id')
|
||||||
category: str = Field(foreign_key='category.name')
|
category: str = Field(foreign_key='category.name')
|
||||||
in_menu: bool = False
|
in_menu: bool = False
|
||||||
|
# Subclasses must include:
|
||||||
|
# project: Project = Relationship()
|
||||||
|
# category_info: Project = Relationship()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def dyn_join_with(cls):
|
def selectinload(cls):
|
||||||
return {
|
return [
|
||||||
'project': Project.on(cls.project_id == Project.id),
|
cls.project,
|
||||||
'category_info': Category.on(cls.category == Category.name),
|
cls.category_info
|
||||||
}
|
]
|
||||||
|
|
||||||
|
# @classmethod
|
||||||
|
# def dyn_join_with(cls):
|
||||||
|
# return {
|
||||||
|
# 'project': Project.on(cls.project_id == Project.id),
|
||||||
|
# 'category_info': Category.on(cls.category == Category.name),
|
||||||
|
# }
|
||||||
|
|
||||||
#id = db.Column(db.BigInteger, primary_key=True)
|
#id = db.Column(db.BigInteger, primary_key=True)
|
||||||
## XXX: Can remove the rest since it's is in the GeoPointSurveyModel class?
|
## XXX: Can remove the rest since it's is in the GeoPointSurveyModel class?
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
from sqlmodel import Field
|
from sqlmodel import Field, Relationship
|
||||||
|
|
||||||
from gisaf.models.models_base import Model
|
from gisaf.models.models_base import Model
|
||||||
from gisaf.models.metadata import gisaf_survey
|
from gisaf.models.metadata import gisaf_survey
|
||||||
|
|
||||||
|
|
||||||
class Accuracy(Model):
|
class Accuracy(Model, table=True):
|
||||||
metadata = gisaf_survey
|
metadata = gisaf_survey
|
||||||
|
|
||||||
class Admin:
|
class Admin:
|
||||||
|
@ -24,7 +24,7 @@ class Accuracy(Model):
|
||||||
return f'<models.Accuracy {self.name}>'
|
return f'<models.Accuracy {self.name}>'
|
||||||
|
|
||||||
|
|
||||||
class Surveyor(Model):
|
class Surveyor(Model, table=True):
|
||||||
metadata = gisaf_survey
|
metadata = gisaf_survey
|
||||||
|
|
||||||
class Admin:
|
class Admin:
|
||||||
|
@ -41,7 +41,7 @@ class Surveyor(Model):
|
||||||
return f'<models.Surveyor {self.name}>'
|
return f'<models.Surveyor {self.name}>'
|
||||||
|
|
||||||
|
|
||||||
class Equipment(Model):
|
class Equipment(Model, table=True):
|
||||||
metadata = gisaf_survey
|
metadata = gisaf_survey
|
||||||
|
|
||||||
class Admin:
|
class Admin:
|
||||||
|
@ -61,7 +61,7 @@ class GeometryType(str, Enum):
|
||||||
point = 'Point'
|
point = 'Point'
|
||||||
line_work = 'Line_work'
|
line_work = 'Line_work'
|
||||||
|
|
||||||
class AccuracyEquimentSurveyorMapping(Model):
|
class AccuracyEquimentSurveyorMapping(Model, table=True):
|
||||||
metadata = gisaf_survey
|
metadata = gisaf_survey
|
||||||
__tablename__ = 'accuracy_equiment_surveyor_mapping'
|
__tablename__ = 'accuracy_equiment_surveyor_mapping'
|
||||||
|
|
||||||
|
@ -73,12 +73,22 @@ class AccuracyEquimentSurveyorMapping(Model):
|
||||||
equipment_id: int = Field(foreign_key='equipment.id', index=True)
|
equipment_id: int = Field(foreign_key='equipment.id', index=True)
|
||||||
geometry_type: GeometryType = Field(default='Point', index=True)
|
geometry_type: GeometryType = Field(default='Point', index=True)
|
||||||
accuracy_id: int = Field(foreign_key='accuracy.id')
|
accuracy_id: int = Field(foreign_key='accuracy.id')
|
||||||
|
surveyor: Surveyor = Relationship()
|
||||||
|
accuracy: Accuracy = Relationship()
|
||||||
|
equipment: Equipment = Relationship()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def dyn_join_with(cls):
|
def selectinload(cls):
|
||||||
return {
|
return [
|
||||||
'surveyor': Surveyor,
|
cls.surveyor,
|
||||||
'equipment': Equipment,
|
cls.equipment,
|
||||||
'accuracy': Accuracy,
|
cls.accuracy,
|
||||||
}
|
]
|
||||||
|
|
||||||
|
# @classmethod
|
||||||
|
# def dyn_join_with(cls):
|
||||||
|
# return {
|
||||||
|
# 'surveyor': Surveyor,
|
||||||
|
# 'equipment': Equipment,
|
||||||
|
# 'accuracy': Accuracy,
|
||||||
|
# }
|
Loading…
Add table
Add a link
Reference in a new issue