Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selecting struct with ORM does not get deeply nested struct_field []arr @[fkey: 'some_id'] #23340

Open
islonely opened this issue Jan 2, 2025 · 0 comments
Labels
ORM Bugs/feature requests, that are related to the V ORM.

Comments

@islonely
Copy link
Contributor

islonely commented Jan 2, 2025

V doctor:

V full version: V 0.4.9 4225a34.42222e6
OS: macos, macOS, 15.1.1, 24B91
Processor: 8 cpus, 64bit, little endian, Apple M3

getwd: /Users/adamoates/Documents/marionville
vexe: /Users/adamoates/v/v
vexe mtime: 2025-01-01 19:24:10

vroot: OK, value: /Users/adamoates/v
VMODULES: OK, value: /Users/adamoates/.vmodules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.39.5 (Apple Git-154)
Git vroot status: weekly.2024.53-6-g42222e6c (4 commit(s) behind V master)
.git/config present: true

CC version: Apple clang version 16.0.0 (clang-1600.0.26.4)
emcc version: N/A
thirdparty/tcc status: thirdparty-macos-arm64 713692d4

What did you do?
./v -g -o vdbg cmd/v && ./vdbg /Users/adamoates/Documents/test.v

import db.sqlite

struct GrandChild {
pub mut:
	id int @[primary; sql: serial]
	child_id int
	name string
}

struct Child {
pub mut:
	id int @[primary; sql: serial]
	parent_id int
	name string
	grandchildren []GrandChild @[fkey: 'child_id']
}

struct Parent {
pub mut:
	id int @[primary; sql: serial]
	name string
	children []Child @[fkey: 'parent_id']
}

fn main() {
	mut db := sqlite.connect(':memory:')!
	parent := Parent{
		name: 'p'
		children: [
			Child{name: 'c1', grandchildren: [
				GrandChild{name: 'gc1'}
				GrandChild{name: 'gc2'}
				GrandChild{name: 'gc3'}
			]},
			Child{name: 'c2'},
			Child{name: 'c3'}
		]
	}
	sql db {
		create table GrandChild
		create table Child
		create table Parent
		insert parent into Parent
	}!
	println(sql db { select from Parent }!)
}

What did you expect to see?

Expected output to have grandchildren listed.

Parent{
    id: 0
    name: 'p'
    children: [Child{
        id: 0
        parent_id: 0
        name: 'c1'
        grandchildren: [GrandChild{
            id: 1
            child_id: 1
            name: 'gc1'
        }, GrandChild{
            id: 2
            child_id: 1
            name: 'gc2'
        }, GrandChild{
            id: 3
            child_id: 1
            name: 'gc3'
        }]
    }, Child{
        id: 0
        parent_id: 0
        name: 'c2'
        grandchildren: []
    }, Child{
        id: 0
        parent_id: 0
        name: 'c3'
        grandchildren: []
    }]
}

What did you see instead?

[Parent{
    id: 1
    name: 'p'
    children: [Child{
        id: 1
        parent_id: 1
        name: 'c1'
        grandchildren: []
    }, Child{
        id: 2
        parent_id: 1
        name: 'c2'
        grandchildren: []
    }, Child{
        id: 3
        parent_id: 1
        name: 'c3'
        grandchildren: []
    }]
}]

Huly®: V_0.6-21771

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.

@felipensp felipensp added the ORM Bugs/feature requests, that are related to the V ORM. label Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ORM Bugs/feature requests, that are related to the V ORM.
Projects
None yet
Development

No branches or pull requests

2 participants