Skip to content

Commit

Permalink
Merge pull request #49101 from xfifix/fix/sti_class_name
Browse files Browse the repository at this point in the history
[Fix #48925] fix "class_name" required for STI class
  • Loading branch information
byroot committed Sep 1, 2023
1 parent 729dfda commit c1150f4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
* Fix associations to a STI model including a `class_name` parameter

```ruby
class Product < ApplicationRecord
has_many :requests, as: :requestable, class_name: "ProductRequest", dependent: :destroy
end

# STI tables
class Request < ApplicationRecord
belongs_to :requestable, polymorphic: true

validate :request_type, presence: true
end

class ProductRequest < Request
belongs_to :user
end
```

Accessing such association would lead to:

```
table_metadata.rb:22:in `has_column?': undefined method `key?' for nil:NilClass (NoMethodError)
```
*Romain Filinto*
* Fix `change_table` setting datetime precision for 6.1 Migrations
*Hartley McGuire*
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/table_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def type(column_name)
end

def has_column?(column_name)
klass&.columns_hash.key?(column_name)
klass&.columns_hash&.key?(column_name)
end

def associated_with?(table_name)
Expand Down

0 comments on commit c1150f4

Please sign in to comment.