diff options
author | Mauro George <maurogot@gmail.com> | 2015-07-02 18:58:19 -0300 |
---|---|---|
committer | Mauro George <maurogot@gmail.com> | 2015-07-16 18:24:39 -0300 |
commit | 2ef1de02ed2e19638aebdbca1aea209a7591b5fe (patch) | |
tree | a855c190d098e0bc05c153eb5f615970d5fcfbf6 /guides | |
parent | cc7ef0cf19d9818c6772e77ca4a8d350688b44e8 (diff) | |
download | rails-2ef1de02ed2e19638aebdbca1aea209a7591b5fe.tar.gz rails-2ef1de02ed2e19638aebdbca1aea209a7591b5fe.tar.bz2 rails-2ef1de02ed2e19638aebdbca1aea209a7591b5fe.zip |
Add a note about default_scope and create records
[ci skip]
Diffstat (limited to 'guides')
-rw-r--r-- | guides/source/active_record_querying.md | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index e3cfabb327..4b4d70d3ce 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -1266,6 +1266,18 @@ class Client < ActiveRecord::Base end ``` +NOTE: The `default_scope` is also applied while creating/building a record. +It is not applied while updating a record. E.g.: + +```ruby +class Client < ActiveRecord::Base + default_scope { where(active: true) } +end + +Client.new # => #<Client id: nil, active: true> +Client.unscoped.new # => #<Client id: nil, active: nil> +``` + ### Merging of scopes Just like `where` clauses scopes are merged using `AND` conditions. |