gorm可以设置的关联关系tag如下:
many2many 指定连接表
foreignkey 设置外键 //这个用的比较多,其实是给被关联表设置外键 或者 通过这个外键进行关联查询,默认是 主表模型_id。比如:user表 user_profile表,就需要将user表的id和user_profile表的user_id关联
references 指定引用的表中的字段 //这个用的也比较多,其实是给主表设置和被关联表外键相关的一个字段,默认是id
association_foreignKey 设置当前表中关联的外键字段//
polymorphic 指定多态类型
polymorphic_value 指定多态值
jointable_foreignkey 指定连接表的外键
association_jointable_foreignkey 指定连接表的关联外键
save_associations 是否自动完成 save 的相关操作
association_autoupdate 是否自动完成 update 的相关操作
association_autocreate 是否自动完成 create 的相关操作
association_save_reference 是否自动完成引用的 save 的相关操作
Tag Description
foreignKey Specifies column name of the current model that is used as a foreign key to the join table
references Specifies column name of the reference’s table that is mapped to the foreign key of the join table
polymorphic Specifies polymorphic type such as model name
polymorphicValue Specifies polymorphic value, default table name
many2many Specifies join table name
joinForeignKey Specifies foreign key column name of join table that maps to the current table
joinReferences Specifies foreign key column name of join table that maps to the reference’s table
constraint Relations constraint, e.g: OnUpdate,OnDelete
