简体   繁体   English

在 buffalo model 中指定多对多关系

[英]Specify many-to-many relationship in buffalo model

Please does anyone know how to specify a many-to-many relationship in buffalo models?请问有人知道如何在水牛模型中指定多对多关系吗?

gobuffalo many_to_many... gobuffalo many_to_many...

type Organization struct {
    ID               int                `json:"id" db:"id"`
    Users            Users              `many_to_many:"user_organizations"`
}


type User struct {
    ID                int                `json:"id" db:"id"`
    Organizations     Organizations      `many_to_many:"user_organizations" json:"-"`
}


type UserOrganization struct {
    ID             int          `json:"id" db:"id"`
    OrganizationID int          `json:"organization_id" db:"organization_id"`
    UserID         int          `json:"user_id" db:"user_id"`
    User           User         `belongs_to:"users"`
    Organization   Organization `belongs_to:"organizations"`
}

Each of these structs are in their own models/*.go file这些结构中的每一个都在它们自己的模型/*.go 文件中

https://gobuffalo.io/en/docs/db/relations https://gobuffalo.io/en/docs/db/relations

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM