entc/gen: use custom id type in join table (#165)

Summary:
Pull Request resolved: https://github.com/facebookincubator/ent/pull/165

Only when it's provided by the use explicitly

Reviewed By: alexsn

Differential Revision: D18506319

fbshipit-source-id: 4cc0bb2c3bbb26f8b27b12e4aa01407fb604928d
This commit is contained in:
Ariel Mashraki
2019-11-14 09:45:55 -08:00
committed by Facebook Github Bot
parent d9da7243f9
commit 38002e6d2e

View File

@@ -331,9 +331,14 @@ func (g *Graph) Tables() (all []*schema.Table) {
})
case M2M:
t1, t2 := tables[n.Table()], tables[e.Type.Table()]
fk1, fk2 := n.ID, e.Type.ID
c1 := &schema.Column{Name: e.Rel.Columns[0], Type: fk1.Type.Type}
c2 := &schema.Column{Name: e.Rel.Columns[1], Type: fk2.Type.Type}
c1 := &schema.Column{Name: e.Rel.Columns[0], Type: field.TypeInt}
if ref := n.ID; ref.UserDefined {
c1.Type = ref.Type.Type
}
c2 := &schema.Column{Name: e.Rel.Columns[1], Type: field.TypeInt}
if ref := e.Type.ID; ref.UserDefined {
c2.Type = ref.Type.Type
}
all = append(all, &schema.Table{
Name: e.Rel.Table,
Columns: []*schema.Column{c1, c2},