Skip to content

Commit

Permalink
add handler to unassign many2One (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuret authored Feb 23, 2024
1 parent 462cbb1 commit 5d0a229
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func (f *Float) Get() float64 {}

```go
func NewMany2One(id int64, name string) *Many2One {}
func NewUnassignedMany2One() *Many2One {}
func (m *Many2One) Get() int64 {}

func NewRelation() *Relation {}
Expand Down
6 changes: 5 additions & 1 deletion conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ func convertFromStaticToDynamicValue(staticValue interface{}) interface{} {
case *Float:
v = sv.v
case *Many2One:
v = sv.ID
if sv.ID == 0 {
v = false
} else {
v = sv.ID
}
case *Relation:
v = sv.v
default:
Expand Down
5 changes: 5 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ func NewMany2One(id int64, name string) *Many2One {
return &Many2One{ID: id, Name: name}
}

// NewUnassignedMany2One create *Many2One value that once set will unassign the current value.
func NewUnassignedMany2One() *Many2One {
return &Many2One{}
}

// Get *Many2One value.
func (m *Many2One) Get() int64 {
return m.ID
Expand Down

0 comments on commit 5d0a229

Please sign in to comment.