diff options
author | Jon Moss <maclover7@users.noreply.github.com> | 2017-04-01 11:28:50 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-01 11:28:50 -0500 |
commit | 99a7be08b464e0ca04ce4c541914f0ff73105bbb (patch) | |
tree | cd834da2a44bef38f5077c72f3917f7260850f5a /guides/source | |
parent | 56014880a2d25416befbd2e440fc94c2b66a0026 (diff) | |
parent | 9aeba503c4bc321e4c5a14cd9c9fbf9fbcc60edb (diff) | |
download | rails-99a7be08b464e0ca04ce4c541914f0ff73105bbb.tar.gz rails-99a7be08b464e0ca04ce4c541914f0ff73105bbb.tar.bz2 rails-99a7be08b464e0ca04ce4c541914f0ff73105bbb.zip |
Merge pull request #28629 from rossta/patch-4
Add default_scope note to ActiveRecord guide
Diffstat (limited to 'guides/source')
-rw-r--r-- | guides/source/active_record_querying.md | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 2902c5d677..26d01d4ede 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -1381,8 +1381,9 @@ class Client < ApplicationRecord end ``` -NOTE: The `default_scope` is also applied while creating/building a record. -It is not applied while updating a record. E.g.: +NOTE: The `default_scope` is also applied while creating/building a record +when the scope arguments are given as a `Hash`. It is not applied while +updating a record. E.g.: ```ruby class Client < ApplicationRecord @@ -1393,6 +1394,17 @@ Client.new # => #<Client id: nil, active: true> Client.unscoped.new # => #<Client id: nil, active: nil> ``` +Be aware that, when given in the `Array` format, `default_scope` query arguments +cannot be converted to a `Hash` for default attribute assignment. E.g.: + +```ruby +class Client < ApplicationRecord + default_scope { where("active = ?", true) } +end + +Client.new # => #<Client id: nil, active: nil> +``` + ### Merging of scopes Just like `where` clauses scopes are merged using `AND` conditions. |