Skip to content

Commit 99bbc0c

Browse files
committed
fix: create method loading relationships REFS #61
the method in the package simply refreshed the model post create and returned it to the calling function, while this will load the identifier but it won't load any dynamically configured relationships we previous fixed this by introducing a _base_get_query in issue #41 the create method now calls the method to get a fully populated model
1 parent d7218c5 commit 99bbc0c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/labs/models/utils.py

+8
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ async def create(
115115
async_db_session.add(new_instance)
116116
await async_db_session.commit()
117117
await async_db_session.refresh(new_instance) # Ensure we get the id
118+
119+
# This will trigger using the _base_get_query to load any
120+
# relationships we need.
121+
updated_instance = await cls.get(
122+
async_db_session,
123+
new_instance.id
124+
)
125+
return updated_instance
118126
return new_instance
119127

120128
@classmethod

0 commit comments

Comments
 (0)