-
Notifications
You must be signed in to change notification settings - Fork 0
/
relationship.go
48 lines (40 loc) · 1.04 KB
/
relationship.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Content managed by Project Forge, see [projectforge.md] for details.
package model
import (
"fmt"
"strings"
"admini.dev/admini/app/util"
)
type Relationship struct {
Key string `json:"key"`
SourceFields []string `json:"srcFields"`
TargetPkg util.Pkg `json:"tgtPackage"`
TargetModel string `json:"tgtModel"`
TargetFields []string `json:"tgtFields"`
}
func (r *Relationship) String() string {
return fmt.Sprintf("%s: [%s] -> %s[%s]", r.Key, strings.Join(r.SourceFields, ", "), r.TargetModel, strings.Join(r.TargetFields, ", "))
}
func (r *Relationship) Path() string {
return strings.Join(append(r.TargetPkg, r.TargetModel), "/")
}
type Relationships []*Relationship
func (s Relationships) Get(key string) *Relationship {
for _, x := range s {
if x.Key == key {
return x
}
}
return nil
}
func (m *Model) ApplicableRelations(key string) Relationships {
ret := Relationships{}
for _, r := range m.Relationships {
for _, sf := range r.SourceFields {
if sf == key {
ret = append(ret, r)
}
}
}
return ret
}