Skip to content

Commit

Permalink
Fix issue when saving a model without any changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yacine Petitprez committed May 25, 2018
1 parent fd89cfb commit a87091f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spec/model/model_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ module ModelSpec
u.id.should eq(1)

u = User.query.find_or_create({last_name: "Henry"}) do |u|
u.first_name = "King" #<< This should not be triggered since we found the row
u.first_name = "Thierry" #<< This should not be triggered since we found the row
end
u.first_name.should eq("Thierry")
u.last_name.should eq("Henry")
Expand Down
2 changes: 1 addition & 1 deletion src/clear/model/modules/has_saving.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Clear::Model::HasSaving
raise Clear::Model::ReadOnlyModelError.new("The model is read-only") if self.class.read_only?

with_triggers(:save) do
if valid?
if valid? && changed?
if persisted?
Clear::SQL.update(self.class.table).set(update_h).where { var("#{self.class.pkey}") == pkey }.execute
else
Expand Down

0 comments on commit a87091f

Please sign in to comment.