Skip to content

Commit

Permalink
#119: Add comments to related entity logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Mar 25, 2021
1 parent ae63c89 commit a0c966e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion datagateway_api/common/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
1 change: 1 addition & 0 deletions datagateway_api/src/resources/entities/entity_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand Down

0 comments on commit a0c966e

Please sign in to comment.