25-polymorphism
Polymorphism Association
GORM supports polymorphism association for has one
and has many
, it will save owned entity’s table name into polymorphic type’s field, primary key value into the polymorphic field
By default polymorphic:<value>
will prefix the column type and column id with <value>
.
The value will be the table name pluralized.
1 |
|
You can specify polymorphism properties separately using the following GORM tags:
polymorphicType
: Specifies the column type.polymorphicId
: Specifies the column ID.polymorphicValue
: Specifies the value of the type.
1 |
|
In these examples, we’ve used a has-many relationship, but the same principles apply to has-one relationships.
25-polymorphism
https://flepeng.github.io/021-Go-34-框架-41-Gorm-V2-25-polymorphism/