Please does anyone know how to specify a many-to-many relationship in buffalo models?
Asked
Active
Viewed 524 times
0
-
1What have you tried? Include your code. What problems did you encounter? – Jonathan Hall Oct 16 '19 at 12:45
-
On the documentation for buffalo, only one to one, and one-to-many relationship was specified. That is reason for the question. – Odohi David Oct 16 '19 at 12:48
1 Answers
3
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

jcfollower
- 3,103
- 19
- 25