73
73
),
74
74
]
75
75
76
+
76
77
class IdentifierMixin (object ):
77
78
"""An ID for a given object
78
79
@@ -81,7 +82,8 @@ class IdentifierMixin(object):
81
82
techniques.
82
83
"""
83
84
id : Mapped [pk_uuid ]
84
-
85
+
86
+
85
87
class DateTimeMixin (object ):
86
88
"""Stores creation and update timestamps
87
89
@@ -96,6 +98,7 @@ class DateTimeMixin(object):
96
98
updated_at : Mapped [timestamp_req ]
97
99
deleted_at : Mapped [timestamp ]
98
100
101
+
99
102
class CUDByMixin (object ):
100
103
""" Adds references to created_by and updated_by users
101
104
@@ -104,6 +107,7 @@ class CUDByMixin(object):
104
107
last_updated_by_user_id : Mapped [fk_user_uuid_req ]
105
108
deleted_by_user_id : Mapped [fk_user_uuid ]
106
109
110
+
107
111
class ModelCRUDMixin :
108
112
"""
109
113
A CRUD Mixin designed to abstract CRUD operations for all
@@ -134,14 +138,17 @@ async def create(
134
138
new_instance = cls (** kwargs )
135
139
async_db_session .add (new_instance )
136
140
await async_db_session .commit ()
137
- await async_db_session .refresh (new_instance ) # Ensure we get the id
141
+ await async_db_session .refresh (new_instance ) # Ensure we get the id
138
142
139
143
# This will trigger using the _base_get_query to load any
140
- # relationships we need.
141
- updated_instance = await cls .get (
142
- async_db_session ,
143
- new_instance .id
144
- )
144
+ # relationships we need. The if statement is to ensure that tables
145
+ # like join tables do not always have an id field.
146
+ updated_instance = new_instance
147
+ if hasattr (cls , "id" ):
148
+ updated_instance = await cls .get (
149
+ async_db_session ,
150
+ new_instance .id
151
+ )
145
152
146
153
return updated_instance
147
154
@@ -257,7 +264,6 @@ async def get_all_in_range(
257
264
users = users .scalars ().all ()
258
265
return users
259
266
260
-
261
267
@classmethod
262
268
async def get_all (
263
269
cls ,
0 commit comments