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.
type Dog struct { |
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.
type Dog struct { |
In these examples, we’ve used a has-many relationship, but the same principles apply to has-one relationships.