From 84942c60b8f8ec1523a8dca67a1c61570703bd88 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 8 Jan 2016 09:02:01 +0800 Subject: [PATCH] Include tag settings when clone a StructField --- field_test.go | 11 +++++++++++ model_struct.go | 1 + 2 files changed, 12 insertions(+) diff --git a/field_test.go b/field_test.go index d19b3b1b..2172b059 100644 --- a/field_test.go +++ b/field_test.go @@ -11,6 +11,11 @@ type CalculateField struct { Name string Children []CalculateFieldChild Category CalculateFieldCategory + EmbeddedField +} + +type EmbeddedField struct { + EmbeddedName string `sql:"NOT NULL;DEFAULT:'hello'"` } type CalculateFieldChild struct { @@ -31,4 +36,10 @@ func TestCalculateField(t *testing.T) { if fields["children"].Relationship == nil || fields["category"].Relationship == nil { t.Errorf("Should calculate fields correctly for the first time") } + + if field, ok := fields["embedded_name"]; !ok { + t.Errorf("should find embedded field") + } else if _, ok := field.TagSettings["NOT NULL"]; !ok { + t.Errorf("should find embedded field's tag settings") + } } diff --git a/model_struct.go b/model_struct.go index fd7f1324..d80165c8 100644 --- a/model_struct.go +++ b/model_struct.go @@ -79,6 +79,7 @@ func (structField *StructField) clone() *StructField { IsScanner: structField.IsScanner, HasDefaultValue: structField.HasDefaultValue, Tag: structField.Tag, + TagSettings: structField.TagSettings, Struct: structField.Struct, IsForeignKey: structField.IsForeignKey, Relationship: structField.Relationship,