-
Notifications
You must be signed in to change notification settings - Fork 0
/
relation_entity.go
59 lines (49 loc) · 1.4 KB
/
relation_entity.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
49
50
51
52
53
54
55
56
57
58
59
package entity_type
import (
validation "github.com/go-ozzo/ozzo-validation/v4"
"github.com/yaruz/app/pkg/yarus_platform/reference/domain/property"
"github.com/yaruz/app/pkg/yarus_platform/reference/domain/property_type"
)
const (
RelationEntityName = "relation"
RelationTableName = "property"
)
// Relation ...
type Relation struct {
property.Property
UndependedEntityType *EntityType `gorm:"-" json:"undependedEntityType"`
DependedEntityType *EntityType `gorm:"-" json:"dependedEntityType"`
}
func (e *Relation) TableName() string {
return RelationTableName
}
// NewRelation func is a constructor for the Property
func NewRelation() *Relation {
return &Relation{
Property: property.Property{
PropertyTypeID: property_type.IDRelation,
},
}
}
func (e Relation) Validate() error {
err := validation.ValidateStruct(&e,
validation.Field(&e.Property.PropertyTypeID, validation.Required, validation.In(uint(property_type.IDRelation))),
validation.Field(&e.Property.IsRange, validation.In(false)),
)
if err != nil {
return err
}
return e.Property.Validate()
}
func (e *Relation) SetUndependedEntityType(typeID *EntityType) {
e.UndependedEntityType = typeID
}
func (e *Relation) SetDependedEntityType(typeID *EntityType) {
e.DependedEntityType = typeID
}
func (e *Relation) AfterFind() error {
return e.Property.AfterFind()
}
func (e *Relation) BeforeSave() error {
return e.Property.BeforeSave()
}