From 2d401756518b170630fd3d1a825cbef2271068aa Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sat, 2 Nov 2013 18:03:04 +0800 Subject: [PATCH] Puts errors for ptr values --- model.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/model.go b/model.go index 8bb39e58..8c742b14 100644 --- a/model.go +++ b/model.go @@ -130,7 +130,14 @@ func (m *Model) fields(operation string) (fields []Field) { if field.IsPrimaryKey { field.SqlType = getPrimaryKeySqlType(m.driver, field.Value, 0) } else { - switch reflect.TypeOf(field.Value).Kind() { + field_value := reflect.ValueOf(field.Value) + if field_value.Kind() == reflect.Ptr { + if field_value.CanAddr() { + field_value = field_value.Elem() + } + } + + switch field_value.Kind() { case reflect.Slice: field.afterAssociation = true case reflect.Struct: @@ -143,6 +150,8 @@ func (m *Model) fields(operation string) (fields []Field) { field.afterAssociation = true } } + case reflect.Ptr: + debug("Errors when handle ptr sub structs") default: field.SqlType = getSqlType(m.driver, field.Value, 0) }