-
Notifications
You must be signed in to change notification settings - Fork 529
Custom sentinel values
John Hawthorn edited this page Feb 9, 2015
·
3 revisions
DISCLAIMER: I believe this is bad advice except for very specific conditions when using MySQL. I recommend against it unless you notice performance performance problems in your production dataset on your production database. - jhawthorn
Some (FIXME: which?) databases ignore null columns when it comes to resolving unique index
constraints. This means unique constraints that involve nullable columns may be
problematic. Instead of using NULL
to represent a not-deleted row, you can pick
a value that you want paranoia to mean not deleted. Note that you can/should
now apply a NOT NULL
constraint to your deleted_at
column.
Per model:
# pick some value
acts_as_paranoid sentinel_value: DateTime.new(0)
or globally in a rails initializer, e.g. config/initializer/paranoia.rb
Paranoia.default_sentinel_value = DateTime.new(0)