Feature request: Support types for polymorphic associations
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 873
- Forks
- 164
- Avg merge
- 4d 27m
- Merged PRs (30d)
- 9
Description
Take the follow code, which defines a myParent.child relation:
class MyParent < Versions::VersionedApplicationRecord
VALID_CHILD_TYPES = T.let([MyChild1.polymorphic_name, MyChild2.polymorphic_name].freeze, T::Array[String])
has_one :child, polymorphic: true
validates :child_type, presence: true, inclusion: { in: VALID_CHILD_TYPES }
end
In theory, there should be enough information to statically type the child association as T.any(MyChild1, MyChild2). However, what it currently gets typed as is T.untyped. It would be great if this common use-case were supported.
(Note that MyClass1.polymorphic_name is not necessarily the same as MyClass1.name. I believe you can call polymorphic_class_for to map the polymorphic_name to the class instance)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Ruby example and tracing how Tapioca types polymorphic associations. Check how polymorphic_name values map to classes, including polymorphic_class_for, and define done as generating T.any(MyChild1, MyChild2) instead of T.untyped for the association.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100