rails/rails — pull request #12144 by 500tech (2013-09-05 10:16:04+00:00)
Title: Duplicate the through_reflection's scope_chain before changing it. Fixes issue #12004

Duplicate the through_reflection's scope_chain before changing it, otherwise it messes up future queries in certain edge-cases.
Fixes issue [#12004](https://github.com/rails/rails/issues/12004)

The scenario is:
A model has 2 has_many double through polymorphic associations (Inventory has_many Orders, Inventory has_many OrderItems through Orders, Inventory has_many [Plans, Items] through OrderItem polymorphic).
Calling Inventory.first.items messes up the later call to Inventory.first.plans, and vice-versa.

Didn't think a test-case is needed for such a far-fetched edge case. What do you think?