From fb86ecd604a362355827bbf05776b847b0ded9a5 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 5 Feb 2018 21:40:44 +0900 Subject: Make `reflection.klass` raise if `polymorphic?` not to be misused This is an alternative of #31877 to fix #31876 caused by #28808. This issue was caused by a combination of several loose implementation. * finding automatic inverse association of polymorphic without context (caused by #28808) * returning `klass` even if `polymorphic?` (exists before #28808) * loose verification by `valid_inverse_reflection?` (exists before #28808) This makes `klass` raise if `polymorphic?` not to be misused. This issue will not happen unless polymorphic `klass` is misused. Fixes #31876. Closes #31877. --- activerecord/test/schema/schema.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activerecord/test/schema') diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 7d008eecd5..3f4fe16678 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -814,6 +814,7 @@ ActiveRecord::Schema.define do create_table :sponsors, force: true do |t| t.integer :club_id t.references :sponsorable, polymorphic: true, index: false + t.references :sponsor, polymorphic: true, index: false end create_table :string_key_objects, id: false, force: true do |t| @@ -951,6 +952,7 @@ ActiveRecord::Schema.define do t.string :poly_man_without_inverse_type t.integer :horrible_polymorphic_man_id t.string :horrible_polymorphic_man_type + t.references :human, polymorphic: true, index: false end create_table :interests, force: true do |t| -- cgit v1.2.3