sqlboiler/bdb/relationships.go
Aaron L 60f6080e73 Refactor dbdrivers into two packages
- Break dbdrivers into bdb and drivers
- Break each type in dbdrivers into it's own file set.
2016-06-22 23:11:32 -07:00

46 lines
1.1 KiB
Go

package bdb
// ToManyRelationship describes a relationship between two tables where the
// local table has no id, and the foreign table has an id that matches a column
// in the local table.
type ToManyRelationship struct {
Name string
ForeignTable string
ForeignColumn string
}
// ToManyRelationships relationship lookups
// Input should be the sql name of a table like: videos
func ToManyRelationships(table string, tables []Table) []ToManyRelationship {
var relationships []ToManyRelationship
for _, t := range tables {
if t.Name == table {
continue
}
for _, f := range t.FKeys {
if f.ForeignTable != table {
continue
}
// singularName := strmangle.Singular(table)
// standardColName := fmt.Sprintf("%s_id", singularName)
relationship := ToManyRelationship{
ForeignTable: t.Name,
ForeignColumn: f.Column,
}
// if standardColName == f.ForeignColumn {
// relationship.Name = table
// } else {
// relationship.Name = table
// }
relationships = append(relationships, relationship)
}
}
return relationships
}