diff --git a/orm/models_test.go b/orm/models_test.go index b6ae21cf..f42d725e 100644 --- a/orm/models_test.go +++ b/orm/models_test.go @@ -392,6 +392,11 @@ type IntegerPk struct { Value string } +type UintPk struct { + Id uint32 `orm:"pk"` + Name string +} + var DBARGS = struct { Driver string Source string diff --git a/orm/orm.go b/orm/orm.go index 26ebb7c1..6f4b7731 100644 --- a/orm/orm.go +++ b/orm/orm.go @@ -141,7 +141,7 @@ func (o *orm) ReadOrCreate(md interface{}, col1 string, cols ...string) (bool, i } id, vid := int64(0), ind.FieldByIndex(mi.fields.pk.fieldIndex) - if mi.fields.pk.fieldType&IsPostiveIntegerField > 0 { + if mi.fields.pk.fieldType&IsPositiveIntegerField > 0 { id = int64(vid.Uint()) } else { id = vid.Int() diff --git a/orm/orm_test.go b/orm/orm_test.go index 832c7301..0c827c2a 100644 --- a/orm/orm_test.go +++ b/orm/orm_test.go @@ -191,6 +191,7 @@ func TestSyncDb(t *testing.T) { RegisterModel(new(InLine)) RegisterModel(new(InLineOneToOne)) RegisterModel(new(IntegerPk)) + RegisterModel(new(UintPk)) err := RunSyncdb("default", true, Debug) throwFail(t, err) @@ -213,6 +214,7 @@ func TestRegisterModels(t *testing.T) { RegisterModel(new(InLine)) RegisterModel(new(InLineOneToOne)) RegisterModel(new(IntegerPk)) + RegisterModel(new(UintPk)) BootStrap() @@ -2013,3 +2015,26 @@ func TestIntegerPk(t *testing.T) { throwFail(t, AssertIs(out.Value, intPk.Value)) } } + +func TestUintPk(t *testing.T) { + name := "go" + u := &UintPk{ + Id: 8, + Name: name, + } + + created, pk, err := dORM.ReadOrCreate(u, "Id") + throwFail(t, err) + throwFail(t, AssertIs(created, true)) + throwFail(t, AssertIs(u.Name, name)) + + nu := &UintPk{Id: 8} + created, pk, err = dORM.ReadOrCreate(nu, "Id") + throwFail(t, err) + throwFail(t, AssertIs(created, false)) + throwFail(t, AssertIs(nu.Id, u.Id)) + throwFail(t, AssertIs(pk, u.Id)) + throwFail(t, AssertIs(nu.Name, name)) + + dORM.Delete(u) +}