rails--rails/activerecord/lib/active_record/scoping
eileencodes a3343d2456
Allow `reload` to be `default_scoped`
`reload` is not `default_scoped` by default because you could be
creating a record that does not match your default scope and therefore
`reload` wouldn't find the record.

However, in the case of sharding an application you may want `reload` to
support `default_scope` because you'll always have the correct scope
set. To accomplish this I added a new method that checks if there are
any default scopes defined that are set to run for `all_queries`. If
there are then don't `unscope` the find methods.

If there is a case where you do want the default scope to apply to all
queries but be able to turn that off, I've added a `unscoped` option to
`reload`. This would use the original behavior regardless of whether the
`default_scope` was used for all queries.

Additionally, this exposes a new public method `default_scopes?` that
returns true if there are default scopes. If `all_queries` is passed to
`default_scopes?` the method will only return true if there is a default
scope for the model that has `all_queries` set to true. If there are no
default scopes with `all_queries` then it will return false.
2020-12-11 13:24:56 -05:00
..
default.rb Allow `reload` to be `default_scoped` 2020-12-11 13:24:56 -05:00
named.rb Add option for `default_scope` to run on all queries 2020-12-01 11:15:08 -05:00