Skip to content
jbguerraz edited this page Feb 9, 2018 · 1 revision

What is the NilableType construct for?

The NilableType is indeed kinda tricky.

The main issue is Odoo will send a false if a field is not set; so a field of type int64 for instance won't be able to cope with such false value.

We could have decided to use only interface{} type and require go-odoo users to type their fields when they need to but instead we decided to go the strongly typed way (so one doesn't have to care much about fields types).

To do so we had to create a nilable structure which uses only interface{} typed fields (except for Booleans for which false isn't an issue) that is used for loading data from Odoo (https://github.com/skilld-labs/go-odoo/blob/1a704aa783362bf60d190ee4b6815faed265992e/api/client.go#L81 - https://github.com/skilld-labs/go-odoo/blob/1a704aa783362bf60d190ee4b6815faed265992e/api/client.go#L90) and a load method that would inspect the nilable variant of the object in order to create a properly typed one (https://github.com/skilld-labs/go-odoo/blob/c83e3b804cde2da2446df7c00726df18c66374c1/types/types.go#L39) that will then replace the struct the user passed to the Read / SearchRead methods (https://github.com/skilld-labs/go-odoo/blob/1a704aa783362bf60d190ee4b6815faed265992e/api/client.go#L85). All of that being transparent to the go-odoo user

Clone this wiki locally