aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2015-07-18 09:04:54 -0400
committerSean Griffin <sean@seantheprogrammer.com>2015-07-18 09:04:54 -0400
commit2a0a264b39eb99ddf444bbdacf3014868c8896cc (patch)
tree392e440f74b0aa884a3bd7bdad5f74bdf583458a
parent68af63618223c238468af1afb093eb4ccc706761 (diff)
parent2ef1de02ed2e19638aebdbca1aea209a7591b5fe (diff)
downloadrails-2a0a264b39eb99ddf444bbdacf3014868c8896cc.tar.gz
rails-2a0a264b39eb99ddf444bbdacf3014868c8896cc.tar.bz2
rails-2a0a264b39eb99ddf444bbdacf3014868c8896cc.zip
Merge pull request #20763 from maurogeorge/default_scope_create-doc
Add a note about default_scope and create records [ci skip]
-rw-r--r--guides/source/active_record_querying.md12
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.