diff --git a/datagateway_api/common/database/models.py b/datagateway_api/common/database/models.py index 1852def6..d0796c95 100644 --- a/datagateway_api/common/database/models.py +++ b/datagateway_api/common/database/models.py @@ -148,7 +148,15 @@ def _nest_string_include(self, dictionary, include): def get_related_entity(self, entity): """ - Given a string for the related entity name, return the related entity + Given a string for the related entity name, return the related entity. This + function is used to retrieve a related entity as a result of an include filter. + + Some related entities have a plural name (so end with an 's') so this is + checked. If `entity` contains a name which is a singular, `entity` is + uppercased (table names are defined in upper case, as seen in `__tablename__` in + the entity classes lower down in this file). Both related entity name types + (singular and plural) are used to retrieve the actual related entity. + :param entity: String - The name of the entity :return: The entity """ diff --git a/datagateway_api/src/resources/entities/entity_map.py b/datagateway_api/src/resources/entities/entity_map.py index a3b3c023..6bb74659 100644 --- a/datagateway_api/src/resources/entities/entity_map.py +++ b/datagateway_api/src/resources/entities/entity_map.py @@ -76,6 +76,7 @@ def create_entity_models(): or relationship_class.direction.name == "ONETOMANY" ): entity_underscore_strip = relationship_name.strip("_") + # Checking for plurals on a related ICAT entity if entity_underscore_strip[-1] == "s": pascal_case = ( entity_underscore_strip[0].upper() + entity_underscore_strip[1:]