Skip to content

Commit

Permalink
Clean up tamas's recent commit and update CHANGELOG
Browse files Browse the repository at this point in the history
This is a potential breakage of backwards compatibility, but it's
unlikely that anyone would be relying on changed_columns being empty
in an after filter, or new? always returning false even the record
being saved was new.  With this commit, it's easier to code a complex
after_save that needs to differentiate between a freshly inserted
record and one that was updated (instead of using a separate
after_create and after_update filters), or have your after_update
filter act depending on contents of changed_columns (previously,
saving them to a separate instance variable in a before_update
filter was the best way).
  • Loading branch information
jeremyevans committed Jan 25, 2009
1 parent 34867d6 commit 67a1468
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,5 +1,7 @@
=== HEAD

* Don't modify Model#new? and Model#changed_columns when saving a record until after the after hooks have been run (tamas, jeremyevans)

* Database#quote_identifiers= now affects future schema modification statements, even if it is not used before one of the schema modification statements (jeremyevans)

* Fix literalization of blobs when using the PostreSQL JDBC subadapter (jeremyevans)
Expand Down
22 changes: 10 additions & 12 deletions lib/sequel_model/record.rb
Expand Up @@ -212,12 +212,12 @@ def save!(*columns)
if (pk = primary_key) && !(Array === pk) && !@values[pk]
@values[pk] = iid
end
if pk
@this = nil # remove memoized this dataset
do_refresh = true
end
@this = nil if pk
end
after_create
after_save
@new = false
refresh if pk
else
return save_failure(:update) if before_update == false
if columns.empty?
Expand All @@ -227,15 +227,13 @@ def save!(*columns)
this.update(@values.reject{|k, v| !columns.include?(k)})
end
after_update
after_save
if columns.empty?
changed_columns.clear
else
changed_columns.reject!{|c| columns.include?(c)}
end
end
after_save
if columns.empty? || new?
changed_columns.clear
else
changed_columns.reject!{|c| columns.include?(c)}
end
@new = false
refresh if defined?(do_refresh) && do_refresh
self
end

Expand Down

0 comments on commit 67a1468

Please sign in to comment.