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

@[sql: serial] and @[serial] are not the same. #23346

Open
islonely opened this issue Jan 2, 2025 · 2 comments
Open

@[sql: serial] and @[serial] are not the same. #23346

islonely opened this issue Jan 2, 2025 · 2 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.b79257b
OS: macos, macOS, 15.1.1, 24B91
Processor: 8 cpus, 64bit, little endian, Apple M3

getwd: /Users/adamoates/.vmodules/islonely/hex
vexe: /Users/adamoates/v/v
vexe mtime: 2025-01-02 15: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-14-gb79257b7
.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 && /Users/adamoates/Documents/test

import db.sqlite

struct Parent {
	id       int     @[primary; serial]
	children []Child @[fkey: 'parent_id']
}

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

fn main() {
	mut db := sqlite.connect(':memory:')!
	parent := Parent{
		children: [Child{}, Child{}]
	}
	sql db {
		create table Child
		create table Parent
		insert parent into Parent
	}!
	parents := sql db {
		select from Parent limit 1
	}!

	assert parent.children.len == parents[0].children.len
}

What did you see?

/Users/adamoates/Documents/test.v:27: FAIL: fn main.main: assert parent.children.len == parents[0].children.len
  left value: parent.children.len = 2
  right value: parents[0].children.len = 0
V panic: Assertion failed...
v hash: b79257b
0   test                                0x0000000102cb5658 main__main + 5388
1   test                                0x0000000102cb5a60 main + 84
2   dyld                                0x00000001948fc274 start + 2840

What did you expect to see?

Expected code to assert true. Changing the Parent struct to this below fixes the issue. But ORM docs say that @[sql: serial] and @[serial] do the same thing.

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

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.

Huly®: V_0.6-21777

@felipensp felipensp added the ORM Bugs/feature requests, that are related to the V ORM. label Jan 2, 2025
@islonely
Copy link
Contributor Author

islonely commented Jan 4, 2025

I think we should just deprecate @[serial] in favor of @[sql: serial]. Having both violates our one way policy.

@medvednikov
Copy link
Member

I agree.

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

3 participants