mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix eager_loading?
when ordering with Symbol
`eager_loading?` is triggered correctly when using `order` with symbols. ```ruby scope = Post.includes(:comments).order(:"comments.label") => true ```
This commit is contained in:
parent
a41f810305
commit
d5b6e5dabe
3 changed files with 22 additions and 1 deletions
|
@ -1,3 +1,14 @@
|
|||
* Fix `eager_loading?` when ordering with `Symbol`
|
||||
|
||||
`eager_loading?` is triggered correctly when using `order` with symbols.
|
||||
|
||||
```ruby
|
||||
scope = Post.includes(:comments).order(:"comments.label")
|
||||
=> true
|
||||
```
|
||||
|
||||
*Jacopo Beschi*
|
||||
|
||||
* Two change tracking methods are added for `belongs_to` associations.
|
||||
|
||||
The `association_changed?` method (assuming an association named `:association`) returns true
|
||||
|
|
|
@ -1550,7 +1550,7 @@ module ActiveRecord
|
|||
def column_references(order_args)
|
||||
references = order_args.flat_map do |arg|
|
||||
case arg
|
||||
when String
|
||||
when String, Symbol
|
||||
arg
|
||||
when Hash
|
||||
arg.keys
|
||||
|
|
|
@ -1714,6 +1714,16 @@ class RelationTest < ActiveRecord::TestCase
|
|||
assert_not_predicate scope, :eager_loading?
|
||||
end
|
||||
|
||||
def test_order_triggers_eager_loading_when_ordering_using_symbols
|
||||
scope = Post.includes(:comments).order(:"comments.label")
|
||||
assert_predicate scope, :eager_loading?
|
||||
end
|
||||
|
||||
def test_order_doesnt_trigger_eager_loading_when_ordering_using_owner_table_and_symbols
|
||||
scope = Post.includes(:comments).order(:"posts.title")
|
||||
assert_not_predicate scope, :eager_loading?
|
||||
end
|
||||
|
||||
def test_order_triggers_eager_loading_when_ordering_using_hash_syntax
|
||||
scope = Post.includes(:comments).order({ "comments.label": :ASC })
|
||||
assert_predicate scope, :eager_loading?
|
||||
|
|
Loading…
Reference in a new issue