Skip to content

Commit 4ced552

Browse files
Added another compiletime pragma
1 parent 451999b commit 4ced552

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/applications/genericUtils.nim

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ proc getRelatedFieldNameOn*[M: Model](targetTableName: static string, sourceType
5454
raise newException(FieldDefect, errorMsg)
5555

5656

57-
proc getRelatedFieldNameOn*[M: Model, O:Model](targetType: typedesc[O], sourceType: typedesc[M]): string =
57+
proc getRelatedFieldNameOn*[M: Model, O:Model](targetType: typedesc[O], sourceType: typedesc[M]): string {.compileTime.} =
5858
result = getRelatedFieldNameOn(O.table(), sourceType)
5959

6060

tests/tgenericUtil.nim

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import ../src/applications/genericUtils
2+
import std/[unittest, logging, typetraits]
3+
import norm/[pragmas, model]
4+
5+
suite "getRelatedFieldNameOn":
6+
setup:
7+
type A = ref object of Model
8+
name: string
9+
10+
type B = ref object of Model
11+
fk1 {.fk: A.}: int64
12+
fk2 {.fk: A.}: int64
13+
14+
type C = ref object of Model
15+
fk1 {.fk: A.}: int64
16+
17+
test "Given a model with 1 FK on another model, When getting relatedFieldNameOn, Then compile":
18+
check compiles(A.getRelatedFieldNameOn(C)) == true
19+
check A.getRelatedFieldNameOn(C) == "fk1"
20+
21+
test "Given a model with 2 FK on another model, When getting relatedFieldNameOn, Then don't compile":
22+
check compiles(A.getRelatedFieldNameOn(B)) == false

0 commit comments

Comments
 (0)