Skip to content

Commit

Permalink
greatly enhanced SyncChanges class
Browse files Browse the repository at this point in the history
SyncChanges meets the requirements of Container, and
ReversibleContainer.

It doesn't derive from the std::map but the std::map is now as the data
member (composition pattern) and I have exposed/proxied all important
methods like at, size, empty, clear, begin/end, ...

Also it's header only now.

 - updated tests
  • Loading branch information
silverqx committed Aug 5, 2022
1 parent b9b0a7f commit 9e8c0ba
Show file tree
Hide file tree
Showing 6 changed files with 360 additions and 113 deletions.
1 change: 0 additions & 1 deletion cmake/Modules/TinySources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ function(tinyorm_sources out_headers out_sources)
tiny/exceptions/relationnotfounderror.cpp
tiny/exceptions/relationnotloadederror.cpp
tiny/tinytypes.cpp
tiny/types/syncchanges.cpp
tiny/utils/attribute.cpp
)
endif()
Expand Down
10 changes: 5 additions & 5 deletions include/orm/tiny/relations/concerns/interactswithpivottable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,19 +451,19 @@ namespace Concerns
if (detaching && !detach.isEmpty()) {
this->detach(detach);

changes["detached"] = std::move(detach);
changes.at(Detached) = std::move(detach);
}

/* Now we are finally ready to attach the new records. Note that we'll disable
touching until after the entire operation is complete so we don't fire a
ton of touch operations until we are totally done syncing the records. */
changes.merge<typename Related::KeyType>(
changes.template merge<typename Related::KeyType>(
attachNew(idsWithAttributes, current, false));

/* Once we have finished attaching or detaching the records, we will see if we
have done any attaching or detaching, and if we have we will touch these
relationships if they are configured to touch on any database updates. */
if (!changes["attached"].isEmpty() || !changes["updated"].isEmpty())
if (!changes.at(Attached).isEmpty() || !changes.at(Updated_).isEmpty())
touchIfTouching_();

return changes;
Expand Down Expand Up @@ -876,7 +876,7 @@ namespace Concerns
if (!current.contains(id)) {
attach(id, attributes, touch);

changes["attached"] << id;
changes.at(Attached) << id;
}

/* If the pivot record already exists, we'll try to update the attributes
Expand All @@ -886,7 +886,7 @@ namespace Concerns
else if (!attributes.isEmpty() &&
updateExistingPivot(id, attributes, touch)
)
changes["updated"] << id;
changes.at(Updated_) << id;
}

return changes;
Expand Down
Loading

0 comments on commit 9e8c0ba

Please sign in to comment.