Use the more intelligent pluralization method we built when generating findXsByField lookup functions.

This commit is contained in:
Jonathan Bernard 2020-01-02 18:46:03 -06:00
parent 934bb26cf3
commit 61e06842af
2 changed files with 2 additions and 2 deletions

View File

@ -100,7 +100,7 @@ macro generateProcsForModels*(dbType: type, modelTypes: openarray[type]): untype
macro generateLookup*(dbType: type, modelType: type, fields: seq[string]): untyped =
let fieldNames = fields[1].mapIt($it)
let procName = ident("find" & $modelType.getType[1] & "sBy" & fieldNames.mapIt(it.capitalize).join("And"))
let procName = ident("find" & pluralize($modelType.getType[1]) & "By" & fieldNames.mapIt(it.capitalize).join("And"))
# Create proc skeleton
result = quote do:

View File

@ -17,7 +17,7 @@ type
# TODO: more complete implementation
# see https://github.com/blakeembrey/pluralize
proc pluralize(name: string): string =
proc pluralize*(name: string): string =
if name[^2..^1] == "ey": return name[0..^3] & "ies"
if name[^1] == 'y': return name[0..^2] & "ies"
return name & "s"