-
-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Description
Would it be possible to add Polymorphism support for services and repositories? Currently, I've only been able to make Polymorphism work by creating a service for each subclass. Ideally it would work something like this:
AllAlerts = with_polymorphic(Alert, (UnexpectedAlert, ExpectedAlert))
class AlertService(SQLAlchemyAsyncRepositoryService[AllAlerts]):
class Repo(SQLAlchemyAsyncRepository[AllAlerts]):
model_type = AllAlerts
repository_type = RepoAllAlerts is an AliasedClass that contains information about the Polymorphic relation. Just like SQLAlchemy, Advanced Alchemy typing would hint that it's methods return the abstract class.
alert: Alert = await alert_service.create(data)But in practice, it really returns the full Polymorphic identity. I'm not sure how much additional work would be required, but this would be a great boon for services that provide many polymorphic identities.
Originally posted by @njz-cvm in #611 (comment)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels