You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For example, a blog Post and a User may share a polymorphic relation to an Image model. Using a one-to-one polymorphic relation allows you to have a single list of unique images that are used for both blog posts and user accounts.
Below is the model definition for such models.
classUserextendsModel{staticentity='users'
@Num(0)id!: number
@Str('')name!: string
@MorphOne(()=>Image,'imageableId','imageableType')image!: Image|null}classPostextendsModel{staticentity='posts'
@Num(0)id!: number
@Str('')title!: string
@MorphOne(()=>Image,'imageableId','imageableType')image!: Image|null}classImageextendsModel{staticentity='images'
@Num(0)id!: number
@Str('')url!: string
@Num(0)imageableId!: number
@Str(0)imageableType: string}
Let's add MorphOne relationship.
For example, a blog Post and a User may share a polymorphic relation to an Image model. Using a one-to-one polymorphic relation allows you to have a single list of unique images that are used for both blog posts and user accounts.
Below is the model definition for such models.
Then, we fetch models like so:
The text was updated successfully, but these errors were encountered: