Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lorddeveloper committed Oct 12, 2022
1 parent d5de7e1 commit bfaf50c
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions src/masoniteorm/query/QueryBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1487,19 +1487,31 @@ def increment(self, column, value=1):

if model and model.is_loaded():
self.where(model.get_primary_key(), model.get_primary_key_value())
additional.update({model.get_primary_key(): model.get_primary_key_value()})
additional.update({
model.get_primary_key(): model.get_primary_key_value(),
column: int(model.__original_attributes__.get(column, 0)) + abs(value)
})

model.fill(additional)
self.observe_events(model, "updating")

self._updates += (
UpdateQueryExpression(column, value, update_type="increment"),
)

self.set_action("update")
results = self.new_connection().query(self.to_qmark(), self._bindings)

if self.dry:
return self

result = self.new_connection().query(self.to_qmark(), self._bindings)
processed_results = self.get_processor().get_column_value(
self, column, results, id_key, id_value
self, column, result, id_key, id_value
)
if model:
additional[column] = processed_results
model.fill_original(additional)
self.observe_events(model, "updated")

return processed_results

def decrement(self, column, value=1):
Expand All @@ -1526,19 +1538,32 @@ def decrement(self, column, value=1):

if model and model.is_loaded():
self.where(model.get_primary_key(), model.get_primary_key_value())
additional.update({model.get_primary_key(): model.get_primary_key_value()})
additional.update({
model.get_primary_key(): model.get_primary_key_value(),
column: int(model.__original_attributes__.get(column, 0)) - abs(value)
})

model.fill(additional)
self.observe_events(model, "updating")

self._updates += (
UpdateQueryExpression(column, value, update_type="decrement"),
)

self.set_action("update")

if self.dry:
return self

result = self.new_connection().query(self.to_qmark(), self._bindings)
processed_results = self.get_processor().get_column_value(
self, column, result, id_key, id_value
)

if model:
additional[column] = processed_results
model.fill_original(additional)
self.observe_events(model, "updated")
return processed_results

def sum(self, column):
Expand Down

0 comments on commit bfaf50c

Please sign in to comment.