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/models
eileencodes 51660f0191 Fix leaky chain on polymorphic association
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.
2015-03-15 10:39:42 -04:00
..
admin Add line endings to files which are missing them 2015-02-17 13:28:06 -07:00
autoloadable
publisher Fix has_and_belongs_to_many in a namespaced model pointing to a non namespaced model 2014-06-19 14:59:48 -03:00
admin.rb Add line endings to files which are missing them 2015-02-17 13:28:06 -07:00
aircraft.rb
arunit2_model.rb
author.rb Remove all cases of manuallly wrapping Arel::Nodes::Quoted 2014-12-29 11:21:56 -07:00
auto_id.rb ✂️ [ci skip] 2013-09-10 19:49:42 +02:00
binary.rb Add line endings to files which are missing them 2015-02-17 13:28:06 -07:00
bird.rb Deprecate false as the way to halt AR callbacks 2015-01-02 15:31:56 -08:00
book.rb Add more tests for the dirty feature for enums 2014-01-21 12:45:58 -02:00
boolean.rb
bulb.rb Deprecate false as the way to halt AR callbacks 2015-01-02 15:31:56 -08:00
cake_designer.rb scope_chain should not be mutated for other reflections 2013-10-14 11:59:59 -04:00
car.rb Improve consistency of counter caches updating in memory 2015-01-26 12:37:29 -07:00
categorization.rb
category.rb Pass a base relation to build_default_scope when joining 2014-02-21 17:58:40 -05:00
chef.rb Fix leaky chain on polymorphic association 2015-03-15 10:39:42 -04:00
citation.rb More unused associations in AR test models 2013-09-10 19:50:00 +02:00
club.rb Merge pull request #15772 from nbudin/sti_through_bug 2014-06-19 15:07:11 -03:00
college.rb Fix error when using with_options with lambda. 2014-04-03 10:26:37 -03:00
column.rb Fix the test defining the models in the right place 2014-04-04 19:44:17 -03:00
column_name.rb Changing the def self.table_name to self.table_name in the column_name.rb 2013-08-03 23:59:28 +05:30
comment.rb Skip StatementCache for eager loaded associations (Fixes #16761) 2014-09-04 10:05:01 -05:00
company.rb Deprecate ActiveModel::Errors add_on_empty and add_on_blank methods 2015-02-19 14:10:38 +01:00
company_in_module.rb Deprecate ActiveModel::Errors add_on_empty and add_on_blank methods 2015-02-19 14:10:38 +01:00
computer.rb
contact.rb Move writing unknown column exception to null attribute 2014-06-26 09:43:35 -06:00
contract.rb adding a test to demonstrate how to use STI subclasses on the far right 2013-09-27 16:56:49 -07:00
country.rb
course.rb
customer.rb Pass symbol as an argument instead of a block 2014-11-29 11:53:24 +01:00
dashboard.rb
default.rb
department.rb scope_chain should not be mutated for other reflections 2013-10-14 11:59:59 -04:00
developer.rb Ensure HABTM relationships produce valid class names (Fixes #17119) 2014-11-09 11:56:07 -06:00
dog.rb Update other counter caches on destroy 2013-03-20 13:43:07 -07:00
dog_lover.rb Update other counter caches on destroy 2013-03-20 13:43:07 -07:00
drink_designer.rb scope_chain should not be mutated for other reflections 2013-10-14 11:59:59 -04:00
edge.rb
electron.rb Add test case for autosave HasMany with accepts_nested_attributes. 2014-02-08 18:57:26 -02:00
engine.rb
entrant.rb
essay.rb
event.rb Add line endings to files which are missing them 2015-02-17 13:28:06 -07:00
eye.rb
face.rb Address ORA-00972: identifier is too long when tested with Oracle 2014-07-14 21:54:17 +09:00
friendship.rb Refactor Person/Friendship relationships to be more intuitive 2013-03-17 02:11:19 -04:00
guid.rb Add line endings to files which are missing them 2015-02-17 13:28:06 -07:00
hotel.rb Fix leaky chain on polymorphic association 2015-03-15 10:39:42 -04:00
image.rb Add foreign_type option for polymorphic has_one and has_many. 2014-12-08 18:13:15 -02:00
interest.rb Getting rid of the +automatic_inverse_of: false+ option in associations in favor 2013-06-08 10:16:51 -07:00
invoice.rb
item.rb
job.rb
joke.rb
keyboard.rb
legacy_thing.rb
lesson.rb
line_item.rb
liquid.rb rename Relation#uniq to Relation#distinct. #uniq still works. 2013-03-15 14:15:47 +01:00
man.rb Address ORA-00972: identifier is too long when tested with Oracle 2014-07-14 21:54:17 +09:00
matey.rb
member.rb Raise an error for has_one associations which try to go :through a polymorphic association [#17263] 2014-10-15 20:25:09 +07:00
member_detail.rb Getting rid of the +automatic_inverse_of: false+ option in associations in favor 2013-06-08 10:16:51 -07:00
member_type.rb
membership.rb adding a test for sti on middle tables with sorting on RHS 2013-09-23 18:13:08 -07:00
minimalistic.rb
minivan.rb
mixed_case_monkey.rb docs, AR already auto-detects primary keys. Closes #13946. [ci skip] 2014-02-05 08:52:59 +01:00
molecule.rb Add test case for autosave HasMany with accepts_nested_attributes. 2014-02-08 18:57:26 -02:00
movie.rb AR .persisted? throws SystemStackError for an unsaved model with a 2014-03-27 15:01:31 -03:00
notification.rb Add ActiveRecord::Base.suppress 2015-02-18 18:30:05 -05:00
order.rb
organization.rb Add setting of FK for throgh associations while building 2014-05-25 21:08:11 +07:00
owner.rb AR specific length validator to respect marked_for_destruction. 2014-12-30 10:25:58 +01:00
parrot.rb Deprecate false as the way to halt AR callbacks 2015-01-02 15:31:56 -08:00
person.rb Dynamically modified schema and association would not be correctly reset 2014-09-06 23:28:18 +09:00
personal_legacy_thing.rb Dynamically modified schema and association would not be correctly reset 2014-09-06 23:28:18 +09:00
pet.rb Add missing require to inheritance test 2013-04-03 14:48:57 -03:00
pirate.rb Add line endings to files which are missing them 2015-02-17 13:28:06 -07:00
possession.rb
post.rb Added #or to ActiveRecord::Relation 2015-01-28 13:35:55 -07:00
price_estimate.rb
project.rb More unused associations in AR test models 2013-09-10 19:50:00 +02:00
publisher.rb Fix how to compute class name on habtm namespaced. 2014-05-13 11:26:46 -03:00
randomly_named_c1.rb Fixes #18492 2015-01-14 21:36:58 +05:30
rating.rb Revert "Merge pull request #14544 from jefflai2/named_scope_sti" 2014-05-21 12:15:57 -03:00
reader.rb Merge pull request #14573 from habermann24/has_many_through_fix 2014-04-22 17:20:52 -05:00
recipe.rb Fix leaky chain on polymorphic association 2015-03-15 10:39:42 -04:00
record.rb Fix the test defining the models in the right place 2014-04-04 19:44:17 -03:00
reference.rb
reply.rb Add test to AR's counter_cache_test.rb 2013-05-18 17:12:46 +09:00
ship.rb Don't redefine autosave association callbacks in nested attrs 2015-01-28 09:53:38 -07:00
ship_part.rb Always perform validations on nested attribute associations 2015-01-30 07:27:20 -07:00
shop.rb Don't try to get the subclass if the inheritance column doesn't exist 2014-01-14 18:53:45 +05:30
speedometer.rb
sponsor.rb
string_key_object.rb
student.rb Fix error when using with_options with lambda. 2014-04-03 10:26:37 -03:00
subject.rb
subscriber.rb
subscription.rb
tag.rb The source option for has_many => through should accept String 2014-04-09 14:57:30 -03:00
tagging.rb Deprecate automatic counter caches on has_many :through 2014-06-26 07:24:34 -06:00
task.rb
topic.rb changed update counter to act on unscoped model 2013-11-26 09:04:03 -06:00
toy.rb
traffic_light.rb
treasure.rb Don't redefine autosave association callbacks in nested attrs 2015-01-28 09:53:38 -07:00
treaty.rb
tyre.rb Don't perform statement caching for find when called from a scope 2014-12-22 15:38:58 -07:00
user.rb Add ActiveRecord::Base.suppress 2015-02-18 18:30:05 -05:00
uuid_child.rb Auto-generate stable fixture UUIDs on PostgreSQL. 2014-01-07 19:05:50 +01:00
uuid_parent.rb Auto-generate stable fixture UUIDs on PostgreSQL. 2014-01-07 19:05:50 +01:00
vegetables.rb
vertex.rb
warehouse_thing.rb
wheel.rb
without_table.rb
zine.rb