Add JoinTable information to relationships.

This commit is contained in:
Aaron L 2016-06-26 17:43:13 -07:00
parent 0d07bb4e67
commit 0fb4739b00
2 changed files with 7 additions and 10 deletions

View file

@ -7,6 +7,7 @@ type ToManyRelationship struct {
Column string
ForeignTable string
ForeignColumn string
ToJoinTable bool
}
// ToManyRelationships relationship lookups
@ -24,21 +25,13 @@ func ToManyRelationships(table string, tables []Table) []ToManyRelationship {
continue
}
// singularName := strmangle.Singular(table)
// standardColName := fmt.Sprintf("%s_id", singularName)
relationship := ToManyRelationship{
Column: f.ForeignColumn,
ForeignTable: t.Name,
ForeignColumn: f.Column,
ToJoinTable: t.IsJoinTable,
}
// if standardColName == f.ForeignColumn {
// relationship.Name = table
// } else {
// relationship.Name = table
// }
relationships = append(relationships, relationship)
}
}

View file

@ -7,7 +7,8 @@ func TestToManyRelationships(t *testing.T) {
tables := []Table{
Table{
Name: "videos",
Name: "videos",
IsJoinTable: true,
FKeys: []ForeignKey{
{Name: "videos_user_id_fk", Column: "user_id", ForeignTable: "users", ForeignColumn: "id"},
{Name: "videos_contest_id_fk", Column: "contest_id", ForeignTable: "contests", ForeignColumn: "id"},
@ -33,4 +34,7 @@ func TestToManyRelationships(t *testing.T) {
if r.ForeignColumn != "user_id" {
t.Error("wrong foreign column:", r.ForeignColumn)
}
if !r.ToJoinTable {
t.Error("expected a join table - kind of - not really but we're faking it")
}
}