Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy reflection_scopes’s unscoped value when building scope for preloading #17360

Merged
merged 1 commit into from
Nov 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ def build_scope
preload_values = preload_scope.values
preload_binds = preload_scope.bind_values

if values[:unscope]
scope.unscope! values[:unscope]
end

scope.where_values = Array(values[:where]) + Array(preload_values[:where])
scope.references_values = Array(values[:references]) + Array(preload_values[:references])
scope.bind_values = (reflection_binds + preload_binds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1895,6 +1895,14 @@ def test_collection_association_with_private_kernel_method
assert_equal [bulb1, bulb2], car.all_bulbs.sort_by(&:id)
end

test 'unscopes the default scope of associated model when used with include' do
car = Car.create!
bulb = Bulb.create! name: "other", car: car

assert_equal bulb, Car.find(car.id).all_bulbs.first
assert_equal bulb, Car.includes(:all_bulbs).find(car.id).all_bulbs.first
end

test "raises RecordNotDestroyed when replaced child can't be destroyed" do
car = Car.create!
original_child = FailedBulb.create!(car: car)
Expand Down