Migrate from dyn_join_with to selectinload

This commit is contained in:
phil 2024-01-03 17:07:11 +05:30
parent be8d7c3175
commit 1e3678fb69
5 changed files with 73 additions and 41 deletions
src/gisaf/models

View file

@ -95,13 +95,21 @@ class BaseSurveyModel(BaseModel):
date: date
@classmethod
def dyn_join_with(cls):
return {
'equipment': Equipment,
'surveyor': Surveyor,
'accuracy': Accuracy,
'project': Project,
}
def selectinload(cls):
return [
cls.equipment,
cls.surveyor,
cls.accuracy,
cls.project,
]
# @classmethod
# def dyn_join_with(cls):
# return {
# 'equipment': Equipment,
# 'surveyor': Surveyor,
# 'accuracy': Accuracy,
# 'project': Project,
# }
#async def get_info(self):
# 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 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.
It can be overridden with the with_related parameter when calling get_df.
"""
@ -371,12 +379,12 @@ class GeoModelNoStatus(Model):
"""
return {}
@classmethod
def get_join_with(cls):
if hasattr(cls, 'dyn_join_with'):
return cls.dyn_join_with()
else:
return cls._join_with
# @classmethod
# def get_join_with(cls):
# if hasattr(cls, 'dyn_join_with'):
# return cls.dyn_join_with()
# else:
# return cls._join_with
#@classmethod
#def get_style(cls):