entc/gen: ignore edge-fields order in edge-schema with composite identifiers (#2719)

This PR allows defining edge schemas with any order of their edges
but still enforce the ordering of the fields in the ID annotation
This commit is contained in:
Ariel Mashraki
2022-07-05 15:45:28 +03:00
committed by GitHub
parent 8c55008a9d
commit 2c1a3555cc
12 changed files with 344 additions and 321 deletions

View File

@@ -69,10 +69,25 @@ func (t *Table) AddColumn(c *Column) *Table {
// HasColumn reports if the table contains a column with the given name.
func (t *Table) HasColumn(name string) bool {
_, ok := t.columns[name]
_, ok := t.Column(name)
return ok
}
// Column returns the column with the given name. If exists.
func (t *Table) Column(name string) (*Column, bool) {
if c, ok := t.columns[name]; ok {
return c, true
}
// In case the column was added
// directly to the Columns field.
for _, c := range t.Columns {
if c.Name == name {
return c, true
}
}
return nil, false
}
// SetAnnotation the entsql.Annotation on the table.
func (t *Table) SetAnnotation(ant *entsql.Annotation) *Table {
t.Annotation = ant