1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/cases/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_scoping_test.rb Allow reload to be default_scoped 2020-12-11 13:24:56 -05:00
named_scoping_test.rb feat(rubocop): Add Style/RedundantRegexpEscape 2020-12-08 18:57:09 +00:00
relation_scoping_test.rb Merge pull request #38319 from kamipo/make_default_scoped_public 2020-01-28 05:53:13 +09:00