Skip to content

Commit

Permalink
Return all the parent catalogue columns in route
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Aug 8, 2024
1 parent d5612e1 commit 85e02c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
7 changes: 4 additions & 3 deletions python/valis/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ class ParentCatalogModel(PeeweeBase):

sdss_id: int
catalogid: int
catalog: str
field_name: str
parent_catalog_id: int | str

# This model is usually instantiated with a dictionary of all the parent
# catalogue columns so we allow extra fields.
model_config = ConfigDict(extra='allow')


class CatalogResponse(CatalogModel, SDSSidFlatBase):
Expand Down
22 changes: 7 additions & 15 deletions python/valis/db/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,24 +701,16 @@ def get_parent_catalog_data(sdss_id: int, catalog: str) -> peewee.ModelSelect:

SID = cat.SDSS_ID_To_Catalog

cat_field: peewee.Field | None = None
cat_pk_name: str | None = None
for field in SID._meta.fields.values():
if '__' not in field.name:
continue
if field.name.split('__')[0] == catalog:
cat_field = field
cat_pk_name = field.name.split('__')[1]
break

if cat_field is None or cat_pk_name is None:
raise ValueError(f'Catalog {catalog} not found in SDSS_ID_To_Catalog table.')
fqtn = f'catalogdb.{catalog}'
if fqtn not in cat.database.models:
raise ValueError(f'Catalog {catalog} not found in catalogdb.')

ParentModel = cat.database.models[fqtn]

return (SID.select(SID.sdss_id,
SID.catalogid,
peewee.Value(catalog).alias('catalog'),
peewee.Value(cat_pk_name).alias('field_name'),
field.alias('parent_catalog_id'))
ParentModel)
.join(ParentModel)
.where(SID.sdss_id == sdss_id)
.order_by(SID.catalogid))

Expand Down

0 comments on commit 85e02c4

Please sign in to comment.