From 0493e786b88ede88f7a2fae0168878f8a36d37b8 Mon Sep 17 00:00:00 2001
From: Konboi <ryosuke.yabuki@gmail.com>
Date: Thu, 30 Mar 2017 11:48:50 +0900
Subject: [PATCH] Fix ToDBName method

from FiledX > fieldx to FieldX > field_x
---
 utils.go      | 3 +++
 utils_test.go | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/utils.go b/utils.go
index ee663f34..97a3d175 100644
--- a/utils.go
+++ b/utils.go
@@ -97,6 +97,9 @@ func ToDBName(name string) string {
 				}
 			} else {
 				buf.WriteRune(v)
+				if i == len(value)-2 && nextCase == upper {
+					buf.WriteRune('_')
+				}
 			}
 		} else {
 			currCase = upper
diff --git a/utils_test.go b/utils_test.go
index 07f5b17f..152296d2 100644
--- a/utils_test.go
+++ b/utils_test.go
@@ -9,11 +9,13 @@ import (
 func TestToDBNameGenerateFriendlyName(t *testing.T) {
 	var maps = map[string]string{
 		"":                          "",
+		"X":                         "x",
 		"ThisIsATest":               "this_is_a_test",
 		"PFAndESI":                  "pf_and_esi",
 		"AbcAndJkl":                 "abc_and_jkl",
 		"EmployeeID":                "employee_id",
 		"SKU_ID":                    "sku_id",
+		"FieldX":                    "field_x",
 		"HTTPAndSMTP":               "http_and_smtp",
 		"HTTPServerHandlerForURLID": "http_server_handler_for_url_id",
 		"UUID":     "uuid",