Skip to content

Broken FKey in ORM. #25568

Description

@K1ndWha1e

Describe the bug

Hi! Tables that use foreign keys are not being created when using an ORM.

Reproduction Steps

import db.sqlite
import time

@[table: 'foos']
struct Foo {
    id          int         @[primary; sql: serial]
    name        string
    created_at  time.Time   @[default: 'CURRENT_TIME']
    updated_at  ?string     @[sql_type: 'TIMESTAMP']
    deleted_at  ?time.Time
    children    []Child     @[fkey: 'parent_id']
}

struct Child {
    id        int    @[primary; sql: serial]
    parent_id int
    name      string
}

fn main() {
    db := sqlite.connect(":memory:")!

    sql db {
        create table Foo
        create table Bar
    }!

    foo := Foo{
    name:       'abc'
    created_at: time.now()
    children: [
        Child{
            name: 'abc'
        },
        Child{
            name: 'def'
        },
    ]
    }
    foo_id := sql db {
        insert foo into Foo
    }!

    result := sql db {
        select from Foo where id == 1
    }!
    println(result)
}

Expected Behavior

[Foo{
    id: 1
    name: 'abc'
    created_at: 2025-10-22 18:13:10
    updated_at: Option(none)       
    deleted_at: Option(none)       
    children: [
        Child{
            name: 'abc'
        },
        Child{
            name: 'def'
        },
]
}]

Current Behavior

[Foo{
    id: 1
    name: 'abc'
    created_at: 2025-10-22 18:13:10
    updated_at: Option(none)       
    deleted_at: Option(none)       
    children: []
}]

Possible Solution

No response

Additional Information/Context

No response

V version

0.4.12 104bc21

Environment details (OS name and version, etc.)

V full version V 0.4.12 c1d1efb.104bc21
OS windows, Њ ©Єа®б®дв Windows 10 Pro 19045 64-а §ап¤­ п
Processor 12 cpus, 64bit, little endian, Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
Memory 48.02GB/63.92GB
V last modified time 2025-10-21 16:52:44
Git version git version 2.47.1.windows.2
V git status weekly.2025.40-93-g104bc212
.git/config present true
cc version cc (Rev6, Built by MSYS2 project) 13.1.0
gcc version gcc (Rev6, Built by MSYS2 project) 13.1.0
clang version N/A
msvc version N/A
tcc version tcc version 0.9.27 (x86_64 Windows)
tcc git status N/A
emcc version N/A
glibc version ldd (cygwin) 2.5.0

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Metadata

Metadata

Assignees

Labels

BugThis tag is applied to issues which reports bugs.ORMBugs/feature requests, that are related to the V ORM.

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions