diff --git a/README.md b/README.md index 822c4fa1..60c5f033 100644 --- a/README.md +++ b/README.md @@ -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 {} diff --git a/conversion.go b/conversion.go index a55d4b62..7addc458 100644 --- a/conversion.go +++ b/conversion.go @@ -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: diff --git a/types.go b/types.go index b9886908..53f8deae 100644 --- a/types.go +++ b/types.go @@ -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