Use the more intelligent pluralization method we built when generating findXsByField lookup functions.
				
					
				
			This commit is contained in:
		| @@ -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: | ||||
|   | ||||
| @@ -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" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user