Skip to content

Commit 0ca2001

Browse files
committed
The properties 'creator', 'creation_time', 'editor', 'update_time' can be filled even if track_changes is set to false
1 parent 44523a6 commit 0ca2001

File tree

3 files changed

+57
-61
lines changed

3 files changed

+57
-61
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PostgresORM"
22
uuid = "748b5efa-ed57-4836-b183-a38105a77fdd"
33
authors = ["Vincent Laugier <vincent.laugier@gmail.com>"]
4-
version = "0.1.4"
4+
version = "0.1.5"
55

66
[deps]
77
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"

src/Controller/coreORM.create.jl

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,37 @@ function create_entity!(new_object::IEntity,
1313

1414
query_string = "INSERT INTO " * table_name
1515

16+
#
17+
# Enrich the created object with the creator and creation time if needed
18+
#
19+
creator_property = util_get_creator_property(orm_module)
20+
if !ismissing(creator_property)
21+
# Only set the creator property if it is empty because the rest of the
22+
# application may want to set it (eg. if importing data)
23+
if ismissing(getproperty(new_object,creator_property))
24+
setproperty!(new_object,
25+
creator_property,
26+
creator)
27+
# If the object has the creator property set, use it
28+
else
29+
creator = getproperty(new_object,creator_property)
30+
end
31+
end
1632

17-
# Record the state of the attributes in the modification table
18-
if util_get_track_changes(orm_module)
19-
20-
#
21-
# Enrich the created object
22-
#
23-
24-
creator_property = util_get_creator_property(orm_module)
25-
if !ismissing(creator_property)
26-
# Only set the creator property if it is empty because the rest of the
27-
# application may want to set it (eg. if importing data)
28-
if ismissing(getproperty(new_object,creator_property))
29-
setproperty!(new_object,
30-
creator_property,
31-
creator)
32-
# If the object has the creator property set, use it
33-
else
34-
creator = getproperty(new_object,creator_property)
35-
end
33+
creation_time_property = util_get_creation_time_property(orm_module)
34+
if !ismissing(creation_time_property)
35+
# Only set the creation time if it is empty because the rest of the
36+
# application may want to set it (eg. if importing data)
37+
if ismissing(getproperty(new_object, creation_time_property))
38+
setproperty!(new_object,
39+
creation_time_property,
40+
now(Dates.UTC))
41+
end
42+
end
3643

37-
end
3844

39-
creation_time_property = util_get_creation_time_property(orm_module)
40-
if !ismissing(creation_time_property)
41-
# Only set the creation time if it is empty because the rest of the
42-
# application may want to set it (eg. if importing data)
43-
if ismissing(getproperty(new_object, creation_time_property))
44-
setproperty!(new_object,
45-
creation_time_property,
46-
now(Dates.UTC))
47-
end
48-
end
45+
# Record the state of the attributes in the modification table
46+
if util_get_track_changes(orm_module)
4947

5048
#
5149
# Create the modification entries
@@ -85,7 +83,7 @@ function create_entity!(new_object::IEntity,
8583

8684
end
8785

88-
end # if track_changes
86+
end # ENDOF if track_changes
8987

9088
props = util_get_entity_props_for_db_actions(new_object,
9189
dbconn,

src/Controller/coreORM.update.jl

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function util_compare_and_sync_entities(previous_entities::Vector{<:IEntity},
8989
else
9090
data_type = typeof(new_entities[1])
9191
end
92-
92+
9393
# ############################################################################## #
9494
# PART1. Identify the indexes of the entities for the different types of actions
9595
# (i.e. remove the entity from the association, create and add an entity to
@@ -328,36 +328,34 @@ function update_entity!(updated_object::IEntity,
328328
return updated_object
329329
end
330330

331-
# Compare versions if needed, by retrieving the current state of the object
332-
# in the database
333-
if util_get_track_changes(orm_module)
331+
#
332+
# Enrich the updated object with the creator and creation time if needed
333+
#
334+
editor_property = util_get_editor_property(orm_module)
335+
if !ismissing(editor_property)
334336

335-
#
336-
# Enrich the updated object
337-
#
338-
editor_property = util_get_editor_property(orm_module)
339-
if !ismissing(editor_property)
340-
341-
# Only set the editor property if it is empty because the rest of the
342-
# application may want to set it (eg. if importing data)
343-
if ismissing(getproperty(updated_object,editor_property))
344-
345-
setproperty!(updated_object,
346-
editor_property,
347-
editor)
348-
# If the object has the creator property set, use it
349-
else
350-
editor = getproperty(updated_object,editor_property)
351-
end
337+
# Only set the editor property if it is empty because the rest of the
338+
# application may want to set it (eg. if importing data)
339+
if ismissing(getproperty(updated_object,editor_property))
352340

341+
setproperty!(updated_object,
342+
editor_property,
343+
editor)
344+
# If the object has the creator property set, use it
345+
else
346+
editor = getproperty(updated_object,editor_property)
347+
end
348+
end
349+
update_time_property = util_get_update_time_property(orm_module)
350+
if !ismissing(update_time_property)
351+
setproperty!(updated_object,
352+
update_time_property,
353+
now(Dates.UTC))
354+
end
353355

354-
end
355-
update_time_property = util_get_update_time_property(orm_module)
356-
if !ismissing(update_time_property)
357-
setproperty!(updated_object,
358-
update_time_property,
359-
now(Dates.UTC))
360-
end
356+
# Compare versions if needed, by retrieving the current state of the object
357+
# in the database
358+
if util_get_track_changes(orm_module)
361359

362360
#
363361
# Create the modification entries
@@ -388,7 +386,7 @@ function update_entity!(updated_object::IEntity,
388386
create_entity!(modif,dbconn)
389387
end
390388

391-
end # if track_changes
389+
end # ENDOF if track_changes
392390

393391
# Create the dictionnary of properties for insertion in the database
394392
props = util_get_entity_props_for_db_actions(updated_object,

0 commit comments

Comments
 (0)