Skip to content

Commit

Permalink
Merge branch '3.x' of https://github.com/MasoniteFramework/orm into 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed Jul 4, 2022
2 parents 5dfc447 + 955da0f commit abac944
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/masoniteorm/connections/BaseConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,6 @@ def select_many(self, query, bindings, amount):
yield result

result = self.format_cursor_results(self._cursor.fetchmany(amount))

def get_row_count(self):
return self._cursor.rowcount
5 changes: 3 additions & 2 deletions src/masoniteorm/models/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,16 +815,17 @@ def save(self, query=False):

if not query:
if self.is_loaded():
result = builder.update(self.__dirty_attributes__)
builder.update(self.__dirty_attributes__)
else:
result = self.create(
self.__dirty_attributes__,
query=query,
id_key=self.get_primary_key(),
)
self.observe_events(self, "saved")
self.fill(result.__attributes__)
self.__dirty_attributes__ = {}
if self.is_loaded():
return self
return result

if self.is_loaded():
Expand Down
15 changes: 10 additions & 5 deletions src/masoniteorm/query/QueryBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,12 +585,14 @@ def delete(self, column=None, value=None, query=False):
self.where(model.get_primary_key(), model.get_primary_key_value())
self.observe_events(model, "deleting")

result = self.new_connection().query(self.to_qmark(), self._bindings)
connection = self.new_connection()

connection.query(self.to_qmark(), self._bindings)

if model:
self.observe_events(model, "deleted")

return result
return connection.get_row_count()

def where(self, column, *args):
"""Specifies a where expression.
Expand Down Expand Up @@ -1413,21 +1415,24 @@ def update(self, updates: dict, dry=False, force=False):

# do not perform update query if no changes
if len(updates.keys()) == 0:
return model if model else self
if dry or self.dry:
return self
return 0

self._updates = (UpdateQueryExpression(updates),)
self.set_action("update")
if dry or self.dry:
return self

additional.update(updates)
connection = self.new_connection()

self.new_connection().query(self.to_qmark(), self._bindings)
connection.query(self.to_qmark(), self._bindings)
if model:
model.fill(updates)
self.observe_events(model, "updated")
model.fill_original(updates)
return model
return connection.get_row_count()
return additional

def force_update(self, updates: dict, dry=False):
Expand Down

0 comments on commit abac944

Please sign in to comment.