|
Ran
|
Jobs
19
|
Files
135
|
Run time
1min
|
Badge
README BADGES
|
push
github
Resolve the inverse of a polymorphic association `has_one :comment, as: :commentable` states that the inverse association on the child is named :commentable, but neither adapter reported it: both read only an explicit :inverse_of option, which such a declaration never has. (ActiveRecord's own reflection does resolve it; the adapter was throwing that away. Mongoid does not resolve it at all, so `as` is the only source available to both - which makes the adapter the right place to normalize this.) Because of that, the nested form for a polymorphic has_one rendered the child's back-reference to its own parent, submitting a blank commentable_type/commentable_id pair. ActiveRecord quietly tolerates that, and so did Mongoid up to 8.x, so the bug went unnoticed under both. Mongoid 9 rejects it outright with Mongoid::Errors::UnrecognizedModelAlias ('Cannot find any model with type ""'), which is how it finally surfaced. nested_field_association? learns nothing new - it already compared field.name against nested_in.inverse_of - but that comparison sat behind a guard requiring the *child* to declare inverse_of, which a polymorphic belongs_to cannot do (its inverse is genuinely ambiguous). Promote it to a branch of its own. The nested-many case has covered this shape since 'hides fields that are deeply nested with inverse_of'; add the missing polymorphic counterpart, which fails under both ORMs without the fix. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> (cherry picked from commit 91e9cca88)
5 of 5 new or added lines in 3 files covered. (100.0%)
4097 of 4271 relevant lines covered (95.93%)
268621.45 hits per line
| Coverage | ∆ | File | Lines | Relevant | Covered | Missed | Hits/Line |
|---|