@PolymorphicField¶
Use @PolymorphicField on a model getter that stores the selected
polymorphic payload.
lib/models.dart
@Model(name: 'Reviews', as: #reviews)
abstract class _Review {
@PolymorphicField(name: 'content', pivotName: 'type')
_ReviewContent get content;
}
The constructor is:
nameis the payload storage name.pivotNameis the discriminator storage name.pivotAscan name the generated Dart pivot field.
Generation produces a discriminator type, a polymorphic value type, and a
concrete generated class for each @PolymorphicData
variant. The selected payload and its discriminator are serialized together.
Use a normal @ModelField for one fixed embedded shape. Use
@PolymorphicField when the payload shape varies according to its
discriminator.