mirror of
https://github.com/hay-kot/homebox.git
synced 2025-07-26 12:30:27 +00:00
refactor schema edges
This commit is contained in:
parent
ccd40ffcac
commit
883468e04c
12 changed files with 499 additions and 460 deletions
|
@ -5,6 +5,8 @@ import (
|
|||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/mixin"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/schema/mixins"
|
||||
)
|
||||
|
||||
|
@ -59,3 +61,35 @@ func (User) Edges() []ent.Edge {
|
|||
}),
|
||||
}
|
||||
}
|
||||
|
||||
// UserMixin when embedded in an ent.Schema, adds a reference to
|
||||
// the Group entity.
|
||||
type UserMixin struct {
|
||||
ref string
|
||||
field string
|
||||
mixin.Schema
|
||||
}
|
||||
|
||||
func (g UserMixin) Fields() []ent.Field {
|
||||
if g.field != "" {
|
||||
return []ent.Field{
|
||||
field.UUID(g.field, uuid.UUID{}),
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (g UserMixin) Edges() []ent.Edge {
|
||||
edge := edge.From("user", User.Type).
|
||||
Ref(g.ref).
|
||||
Unique().
|
||||
Required()
|
||||
|
||||
if g.field != "" {
|
||||
edge = edge.Field(g.field)
|
||||
}
|
||||
|
||||
return []ent.Edge{edge}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue