You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeGroupstruct {
Uuid uuid.UUID`gorm:"primaryKey;column:uuid"`Namestring`gorm:"column:name"`Machines []*Machine`gorm:"many2many:group_machines;foreignKey:Uuid;joinForeignKey:GroupUuid;References:Uuid;joinReferences:MachineUuid"`
}
typeMachinestruct {
Uuid uuid.UUID`gorm:"primaryKey;column:uuid"`Namestring`gorm:"column:name"`Groups []*Group`gorm:"many2many:group_machines;foreignKey:Uuid;joinForeignKey:MachineUuid;References:Uuid;joinReferences:GroupUuid"`
}
// The GroupMachines tables was created automatically, but since I need to keep an order for // the machines in a group, I need to have the Rank. So I created a new struct that I included in the migration.typeGroupMachinesstruct {
GroupUuid uuid.UUID`gorm:"primaryKey;column:group_uuid"`Group*GroupMachineUuid uuid.UUID`gorm:"primaryKey;column:machine_uuid"`Machine*MachineRankint`gorm:"column:rank"`
}
So, my question is how I can preload a group with the machine, ordered by Rank ?
I tried something like that, but that doesn't work:
Your Question
Hi guys,
I have a relation many-to-many like that:
So, my question is how I can preload a group with the machine, ordered by Rank ?
I tried something like that, but that doesn't work:
With that code, I got the following error:
SQL logic error: no such column: group_machines.rank (1)
In fact, I don't necessarily need to have the Rank value, I just need the Machines list in my Group to be ordered correctly.
The document you expected this should be explained
Associations / Preload : indicate how to manage supplementary column in a many-to-many relation.
Expected answer
How to make that work ? :)
The text was updated successfully, but these errors were encountered: