mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
51660f0191
If there was a polymorphic hm:t association with a scope AND second non-scoped hm:t association on a model the polymorphic scope would leak through into the call for the non-polymorhic hm:t association. This would only break if `hotel.drink_designers` was called before `hotel.recipes`. If `hotel.recipes` was called first there would be no problem with the SQL. Before (employable_type should not be here): ``` SELECT COUNT(*) FROM "drink_designers" INNER JOIN "chefs" ON "drink_designers"."id" = "chefs"."employable_id" INNER JOIN "departments" ON "chefs"."department_id" = "departments"."id" WHERE "departments"."hotel_id" = ? AND "chefs"."employable_type" = ? [["hotel_id", 1], ["employable_type", "DrinkDesigner"]] ``` After: ``` SELECT COUNT(*) FROM "recipes" INNER JOIN "chefs" ON "recipes"."chef_id" = "chefs"."id" INNER JOIN "departments" ON "chefs"."department_id" = "departments"."id" WHERE "departments"."hotel_id" = ? [["hotel_id", 1]] ``` From the SQL you can see that `employable_type` was leaking through when calling recipes. The solution is to dup the chain of the polymorphic association so it doesn't get cached. Additionally, this follows `scope_chain` which dup's the `source_reflection`'s `scope_chain`. This required another model/table/relationship because the leak only happens on a hm:t polymorphic that's called before another hm:t on the same model. I am specifically testing the SQL here instead of the number of records becasue the test could pass if there was 1 drink designer recipe for the drink designer chef even though the `employable_type` was leaking through. This needs to specifically check that `employable_type` is not in the SQL statement. |
||
---|---|---|
.. | ||
admin | ||
autoloadable | ||
publisher | ||
admin.rb | ||
aircraft.rb | ||
arunit2_model.rb | ||
author.rb | ||
auto_id.rb | ||
binary.rb | ||
bird.rb | ||
book.rb | ||
boolean.rb | ||
bulb.rb | ||
cake_designer.rb | ||
car.rb | ||
categorization.rb | ||
category.rb | ||
chef.rb | ||
citation.rb | ||
club.rb | ||
college.rb | ||
column.rb | ||
column_name.rb | ||
comment.rb | ||
company.rb | ||
company_in_module.rb | ||
computer.rb | ||
contact.rb | ||
contract.rb | ||
country.rb | ||
course.rb | ||
customer.rb | ||
dashboard.rb | ||
default.rb | ||
department.rb | ||
developer.rb | ||
dog.rb | ||
dog_lover.rb | ||
drink_designer.rb | ||
edge.rb | ||
electron.rb | ||
engine.rb | ||
entrant.rb | ||
essay.rb | ||
event.rb | ||
eye.rb | ||
face.rb | ||
friendship.rb | ||
guid.rb | ||
hotel.rb | ||
image.rb | ||
interest.rb | ||
invoice.rb | ||
item.rb | ||
job.rb | ||
joke.rb | ||
keyboard.rb | ||
legacy_thing.rb | ||
lesson.rb | ||
line_item.rb | ||
liquid.rb | ||
man.rb | ||
matey.rb | ||
member.rb | ||
member_detail.rb | ||
member_type.rb | ||
membership.rb | ||
minimalistic.rb | ||
minivan.rb | ||
mixed_case_monkey.rb | ||
molecule.rb | ||
movie.rb | ||
notification.rb | ||
order.rb | ||
organization.rb | ||
owner.rb | ||
parrot.rb | ||
person.rb | ||
personal_legacy_thing.rb | ||
pet.rb | ||
pirate.rb | ||
possession.rb | ||
post.rb | ||
price_estimate.rb | ||
project.rb | ||
publisher.rb | ||
randomly_named_c1.rb | ||
rating.rb | ||
reader.rb | ||
recipe.rb | ||
record.rb | ||
reference.rb | ||
reply.rb | ||
ship.rb | ||
ship_part.rb | ||
shop.rb | ||
speedometer.rb | ||
sponsor.rb | ||
string_key_object.rb | ||
student.rb | ||
subject.rb | ||
subscriber.rb | ||
subscription.rb | ||
tag.rb | ||
tagging.rb | ||
task.rb | ||
topic.rb | ||
toy.rb | ||
traffic_light.rb | ||
treasure.rb | ||
treaty.rb | ||
tyre.rb | ||
user.rb | ||
uuid_child.rb | ||
uuid_parent.rb | ||
vegetables.rb | ||
vertex.rb | ||
warehouse_thing.rb | ||
wheel.rb | ||
without_table.rb | ||
zine.rb |