diff options
author | Steve Klabnik <steve@steveklabnik.com> | 2012-11-27 08:56:45 -0800 |
---|---|---|
committer | Steve Klabnik <steve@steveklabnik.com> | 2012-11-27 08:56:45 -0800 |
commit | 1ce99553d0dc7c84a9cade9faec8993de0ac6d88 (patch) | |
tree | 6da05de830236dab289b75b84615d6c99aa4de8e | |
parent | cfd324b4b68469ba3188e4b7ba8586e59b239693 (diff) | |
download | rails-1ce99553d0dc7c84a9cade9faec8993de0ac6d88.tar.gz rails-1ce99553d0dc7c84a9cade9faec8993de0ac6d88.tar.bz2 rails-1ce99553d0dc7c84a9cade9faec8993de0ac6d88.zip |
Adding a note about :inverse_of for validations.
From https://github.com/lifo/docrails/commit/cfd324b4b68469ba3188e4b7ba8586e59b239693\#commitcomment-2213592
-rw-r--r-- | guides/source/active_record_validations_callbacks.md | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/guides/source/active_record_validations_callbacks.md b/guides/source/active_record_validations_callbacks.md index 3c6e459453..6f1c0b6c24 100644 --- a/guides/source/active_record_validations_callbacks.md +++ b/guides/source/active_record_validations_callbacks.md @@ -381,6 +381,14 @@ class LineItem < ActiveRecord::Base end ``` +You should also be sure to have a proper `:inverse_of` as well: + +```ruby +class Order < ActiveRecord::Base + has_many :line_items, inverse_of: :order +end +``` + If you validate the presence of an object associated via a `has_one` or `has_many` relationship, it will check that the object is neither `blank?` nor `marked_for_destruction?`. Since `false.blank?` is true, if you want to validate the presence of a boolean field you should use `validates :field_name, inclusion: { in: [true, false] }`. |