Skip to content

Commit

Permalink
Persist aggregate after persisting child entities
Browse files Browse the repository at this point in the history
  • Loading branch information
subhashb committed Apr 28, 2020
1 parent c7de9ee commit 1b29014
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/protean/core/repository/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ def add(self, aggregate): # noqa: C901
logger.error(errors)
raise ValidationError(errors)

# Persist only if the aggregate object is new, or it has changed since last persistence
if ((not aggregate.state_.is_persisted) or
(aggregate.state_.is_persisted and aggregate.state_.is_changed)):
dao = current_domain.get_dao(self.meta_.aggregate_cls)
dao.save(aggregate)

# If there are HasMany fields in the aggregate, sync child objects added/removed,
# but not yet persisted to the database.
#
Expand Down Expand Up @@ -160,6 +154,12 @@ def add(self, aggregate): # noqa: C901
field.change = None
field.change_old_value = None

# Persist only if the aggregate object is new, or it has changed since last persistence
if ((not aggregate.state_.is_persisted) or
(aggregate.state_.is_persisted and aggregate.state_.is_changed)):
dao = current_domain.get_dao(self.meta_.aggregate_cls)
dao.save(aggregate)

return aggregate

def remove(self, aggregate):
Expand Down

0 comments on commit 1b29014

Please sign in to comment.