diff --git a/vlib/orm/orm_test.v b/vlib/orm/orm_test.v index 91c0801127..a1033cc42a 100644 --- a/vlib/orm/orm_test.v +++ b/vlib/orm/orm_test.v @@ -34,6 +34,33 @@ struct TestTime { create time.Time } +fn test_use_struct_field_as_limit() { + db := sqlite.connect(':memory:') or { panic(err) } + + sql db { + create table User + } + + foo := Foo{ + age: 10 + } + + sam := User{ + age: 29 + name: 'Sam' + } + + sql db { + insert sam into User + } + + users := sql db { + select from User limit foo.age + } + + assert users.len == 1 +} + fn test_orm() { db := sqlite.connect(':memory:') or { panic(err) } diff --git a/vlib/v/checker/orm.v b/vlib/v/checker/orm.v index a321f0e41a..fa72b9c4d7 100644 --- a/vlib/v/checker/orm.v +++ b/vlib/v/checker/orm.v @@ -348,6 +348,10 @@ fn (mut c Checker) check_sql_expr_type_is_int(expr &ast.Expr, sql_keyword string if expr.obj.typ.is_int() { return } + } else if expr is ast.SelectorExpr { + if expr.typ.is_int() { + return + } } else if expr is ast.CallExpr { if expr.return_type == 0 { return