rails/activerecord/lib/active_record
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
..
associations Doc fix about association hierarchy 2015-03-15 16:48:07 +09:00
attribute_methods type_cast_from_user -> cast 2015-02-17 13:39:42 -07:00
attribute_set Maintain a consistent order in ActiveRecord::Base#attributes 2015-02-10 08:21:46 -07:00
coders Provide a better error message for unsupported classes in serialize 2014-12-27 19:49:09 -07:00
connection_adapters Fix before_commit when updating a record on the callback 2015-03-14 12:20:36 -04:00
fixture_set
locale Move required error message and changelog to Active Record 2015-02-01 10:31:54 -02:00
locking Call attributes_for_update in _update_record w/ optimistic locking 2015-02-24 14:10:29 -07:00
migration
railties Schema creation doesn't load the app 2015-02-11 14:20:56 -08:00
relation Spell PostgreSQL correctly 🐘 2015-02-28 23:01:08 +09:00
scoping Isolate access to .default_scopes in ActiveRecord::Scoping::Default 2015-03-12 01:22:39 -07:00
serializers Remove most type related predicates from Column 2015-01-30 11:42:54 -07:00
tasks Fixes reference for schema_format to AR::Base from AS::Base 2015-03-03 12:13:18 -05:00
type Some documentation edits [ci skip] 2015-03-05 14:18:09 +01:00
type_caster type_cast_for_database -> serialize 2015-02-17 13:35:23 -07:00
validations type_cast_for_database -> serialize 2015-02-17 13:35:23 -07:00
aggregations.rb Do not test, document or use a private API method 2015-02-20 17:50:20 -02:00
association_relation.rb Properly create through records when called with where 2015-02-26 12:42:55 -07:00
associations.rb remove unnecessary path parameters 2015-03-10 21:29:59 +09:00
attribute_assignment.rb Follow-up to #10776 2015-02-26 15:40:03 +01:00
attribute_decorators.rb Attribute assignment and type casting has nothing to do with columns 2015-01-31 19:42:38 -07:00
attribute_methods.rb Attribute assignment and type casting has nothing to do with columns 2015-01-31 19:42:38 -07:00
attribute_set.rb Significantly improve the performance of _read_attribute on JRuby 2015-02-06 12:10:47 -07:00
attribute.rb type_cast_from_user -> cast 2015-02-17 13:39:42 -07:00
attributes.rb Some documentation edits [ci skip] 2015-03-05 14:18:09 +01:00
autosave_association.rb Always perform validations on nested attribute associations 2015-01-30 07:27:20 -07:00
base.rb Add ActiveRecord::Base.suppress 2015-02-18 18:30:05 -05:00
callbacks.rb Deprecate false as the way to halt AR callbacks 2015-01-02 15:31:56 -08:00
connection_handling.rb Spell PostgreSQL correctly 🐘 2015-02-28 23:01:08 +09:00
core.rb Isolate access to .default_scopes in ActiveRecord::Scoping::Default 2015-03-12 01:22:39 -07:00
counter_cache.rb Improve consistency of counter caches updating in memory 2015-01-26 12:37:29 -07:00
dynamic_matchers.rb Remove support to activerecord-deprecated_finders 2015-01-02 12:06:24 -03:00
enum.rb type_cast_from_user -> cast 2015-02-17 13:39:42 -07:00
errors.rb Follow-up to #10776 2015-02-26 15:40:03 +01:00
explain_registry.rb
explain_subscriber.rb
explain.rb
fixtures.rb Merge pull request #19177 from gregmolnar/fixtures 2015-03-02 18:46:21 -03:00
gem_version.rb Start Rails 5 development 🎉 2014-11-28 15:00:06 -02:00
inheritance.rb Attribute assignment and type casting has nothing to do with columns 2015-01-31 19:42:38 -07:00
integration.rb
legacy_yaml_adapter.rb Add YAML compatibility for objects from Rails 4.2 2015-03-10 11:56:45 -06:00
log_subscriber.rb Remove Relation#bind_params 2015-01-27 16:10:03 -07:00
migration.rb Fix typo [ci skip] 2015-02-23 13:32:54 -05:00
model_schema.rb rm Column#cast_type 2015-02-03 15:02:18 -07:00
nested_attributes.rb type_cast_from_user -> cast 2015-02-17 13:39:42 -07:00
no_touching.rb Add nodoc to touch at no_touching.rb 2014-12-29 14:14:46 -03:00
null_relation.rb Optimize none? and one? relation query methods to use LIMIT and COUNT. 2015-02-12 17:40:59 -02:00
persistence.rb call sync_with_transaction_state inside persisted? then check ivars 2015-03-02 07:51:29 -08:00
query_cache.rb
querying.rb Added #or to ActiveRecord::Relation 2015-01-28 13:35:55 -07:00
railtie.rb Revert "Merge pull request #15476 from JacobEvelyn/master" 2015-03-11 15:06:42 -07:00
readonly_attributes.rb Pass symbol as an argument instead of a block 2014-11-29 11:53:24 +01:00
reflection.rb Fix leaky chain on polymorphic association 2015-03-15 10:39:42 -04:00
relation.rb Optimize none? and one? relation query methods to use LIMIT and COUNT. 2015-02-12 17:40:59 -02:00
result.rb Type#type_cast_from_database -> Type#deserialize 2015-02-17 13:28:48 -07:00
runtime_registry.rb
sanitization.rb type_cast_for_database -> serialize 2015-02-17 13:35:23 -07:00
schema_dumper.rb Improve a dump of the primary key support. 2014-12-29 09:19:21 +09:00
schema_migration.rb
schema.rb
scoping.rb Isolate access to .default_scopes in ActiveRecord::Scoping::Default 2015-03-12 01:22:39 -07:00
secure_token.rb Fix #has_secure_token documentation [ci skip] 2015-02-20 18:52:02 -06:00
serialization.rb Pass symbol as an argument instead of a block 2014-11-29 11:53:24 +01:00
statement_cache.rb Remove Relation#bind_params 2015-01-27 16:10:03 -07:00
store.rb Fix type case of "validations" and word-wrap from #17954 [ci skip] 2014-12-08 08:36:04 -08:00
suppressor.rb Return true instead of self when suppressed 2015-02-19 09:25:20 -02:00
table_metadata.rb Respect custom primary keys for associations in Relation#where 2015-02-04 08:56:46 -07:00
timestamp.rb Fix warning: `*' interpreted as argument prefix 2014-12-28 16:05:53 +09:00
transactions.rb ‘test_after_commit’ gem is not required in Rails 5 remove note from doc 2015-03-10 18:13:07 +05:30
translation.rb
type_caster.rb Extract an explicit type caster class 2014-12-29 11:07:56 -07:00
type.rb Add docs for the type registry 2015-02-17 14:17:59 -07:00
validations.rb Move the validate! method to ActiveModel::Validations. 2015-02-20 16:05:26 -02:00
version.rb