You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-2
Original file line number
Diff line number
Diff line change
@@ -75,7 +75,8 @@ class Post
75
75
:version_field => :version, # adds "field :version, :type => Integer" to track current version, default is :version
76
76
:track_create => true, # track document creation, default is true
77
77
:track_update => true, # track document updates, default is true
78
-
:track_destroy => true# track document destruction, default is true
78
+
:track_destroy => true, # track document destruction, default is true
79
+
:track_blank_changes => false# track changes from blank? to blank?, default is false
79
80
end
80
81
81
82
classComment
@@ -283,6 +284,32 @@ end
283
284
284
285
It will now track only `_id` (Mandatory), `title` and `content` attributes for `pages` relation.
285
286
287
+
### Track all blank changes
288
+
289
+
Normally changes where both the original and modified values respond with `true` to `blank?` (for example `nil` to `false`) aren't tracked. However, there may be cases where it's important to track such changes, for example when a field isn't present (so appears to be `nil`) then is set to `false`. To track such changes, set the `track_blank_changes` option to `true` (it defaults to `false`) when turning on history tracking:
290
+
291
+
```ruby
292
+
classBook
293
+
includeMongoid::Document
294
+
...
295
+
field :summary
296
+
track_history # Use default of false for track_blank_changes
297
+
end
298
+
299
+
# summary change not tracked if summary hasn't been set (or has been set to something that responds true to blank?)
300
+
Book.find(id).update_attributes(:summary => '')
301
+
302
+
classChapter
303
+
includeMongoid::Document
304
+
...
305
+
field :title
306
+
track_history :track_blank_changes => true
307
+
end
308
+
309
+
# title change tracked even if title hasn't been set
310
+
Chapter.find(id).update_attributes(:title => '')
311
+
```
312
+
286
313
### Retrieving the list of tracked static and dynamic fields
287
314
288
315
```ruby
@@ -604,6 +631,6 @@ You're encouraged to contribute to Mongoid History. See [CONTRIBUTING.md](CONTRI
604
631
605
632
## Copyright
606
633
607
-
Copyright (c) 2011-2020 Aaron Qian and Contributors.
634
+
Copyright (c) 2011-2024 Aaron Qian and Contributors.
608
635
609
636
MIT License. See [LICENSE.txt](LICENSE.txt) for further details.
0 commit comments