Skip to content

Commit

Permalink
fixed issue. needs refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed Jan 4, 2024
1 parent 57aa5cf commit 1492f7a
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 7 deletions.
7 changes: 5 additions & 2 deletions cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
# print(builder.where("id", 1).or_where(lambda q: q.where('id', 2).or_where('id', 3)).get())

class User(Model):
__connection__ = "sqlite"
__connection__ = "mysql"
__table__ = "users"
__dates__ = ["verified_at"]

@has_many("id", "user_id")
def articles(self):
Expand All @@ -28,7 +29,9 @@ class Article(Model):

# user = User.create({"name": "phill", "email": "phill"})
# print(inspect.isclass(User))
print(User.find(1).with_("articles").first().serialize())
user = User.first()
user.update({"verified_at": None, "updated_at": None})
print(user.first().serialize())

# print(user.serialize())
# print(User.first())
File renamed without changes.
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[pytest]
env =
D:DB_CONFIG_PATH=config/test-database
D:DB_CONFIG_PATH=config/database
2 changes: 1 addition & 1 deletion src/masoniteorm/connections/BaseConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def statement(self, query, bindings=()):
raise AttributeError(
f"Must set the _cursor attribute on the {self.__class__.__name__} class before calling the 'statement' method."
)

print('qq', query, bindings)
self._cursor.execute(query, bindings)
end = "{:.2f}".format(timer() - start)

Expand Down
14 changes: 12 additions & 2 deletions src/masoniteorm/query/QueryBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1441,13 +1441,21 @@ def update(
date_fields = model.get_dates()
for key, value in updates.items():
if key in date_fields:
updates[key] = model.get_new_datetime_string(value)
if value:
updates[key] = model.get_new_datetime_string(value)
else:
updates[key] = value
# Cast value if necessary
if cast:
updates[key] = model.cast_value(value)
if value:
updates[key] = model.cast_value(value)
else:
updates[key] = value
elif not updates:
# Do not perform query if there are no updates
return self

print('ooo', updates)

self._updates = (UpdateQueryExpression(updates),)
self.set_action("update")
Expand Down Expand Up @@ -2111,6 +2119,8 @@ def to_qmark(self):

sql = grammar.compile(self._action, qmark=True).to_sql()



self._bindings = grammar._bindings

self.reset()
Expand Down
8 changes: 7 additions & 1 deletion src/masoniteorm/scopes/TimeStampsScope.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ def set_timestamp_create(self, builder):
def set_timestamp_update(self, builder):
if not builder._model.__timestamps__:
return builder


print(builder._updates[0])
for update in builder._updates:
if builder._model.date_updated_at in update.column:
print("not updating this is right")
return
print("still updating. this is wrong")
builder._updates += (
UpdateQueryExpression(
{
Expand Down
8 changes: 8 additions & 0 deletions tests/postgres/grammar/test_update_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def test_raw_expression(self):

self.assertEqual(to_sql, sql)

def test_update_null(self):
to_sql = self.builder.update({"name": None}, dry=True).to_sql()
print(to_sql)

sql = ""

self.assertEqual(to_sql, sql)


class TestPostgresUpdateGrammar(BaseTestCaseUpdateGrammar, unittest.TestCase):
grammar = "postgres"
Expand Down

0 comments on commit 1492f7a

Please sign in to comment.