From bd124581cc58ed0a4abc82e08b26fe0f1308852e Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Fri, 26 Jan 2024 22:31:11 +0100 Subject: [PATCH] Handle null strings in I18nInput.FillArray MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Until now i always had the translations be empty strings if some columns did not have the full translation, but this is going too far on the non-NULL policy: surely they have a translations, but we do not know it yet; this is the exact type of situations NULL values are for. Besides the philosophical distinction, having empty strings instead of NULLs is less practical, because i no longer can user coalesce() to retrieve the default language text in case the translation for that particular field is not available, even if the row for a locale exists. In time i will change all _i18n relations, but for now only these from campsite follow the “new policy”. --- pkg/form/input.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/form/input.go b/pkg/form/input.go index 3d6c4b9..d065583 100644 --- a/pkg/form/input.go +++ b/pkg/form/input.go @@ -70,7 +70,12 @@ func (input I18nInput) FillArray(array database.RecordArray) error { if err != nil { return err } - input[tag.String()].Val = el.Fields[1].Get().(string) + val := el.Fields[1].Get() + if val == nil { + input[tag.String()].Val = "" + } else { + input[tag.String()].Val = val.(string) + } } return nil }