Describe the bug
ORM cannot handle nested foreign keys, example:
Reproduction Steps
pub struct Address {
id int [primary; sql: serial; nonull]
create_at string [default: 'now()'; nonull; sql_type: 'TIMESTAMP']
update_at string [default: 'now()'; nonull; sql_type: 'TIMESTAMP']
street string [nonull]
city string [nonull]
state string [nonull]
zip_code string [nonull]
proximity string [nonull]
}
[table: 'RealStates']
pub struct RealState {
id string [primary; sql_type: 'uuid'; default: "uuid_generate_v4()"; nonull]
parent_id int
name string [sql_type: 'varchar(80)'; nonull]
cnpj string [sql_type: 'varchar(14)'; nonull]
address []Address [fkey: 'id']
}
[table: 'Realtors']
pub struct Realtor {
id string [primary; sql_type: 'uuid'; default: "uuid_generate_v4()"; nonull]
first_name string [sql_type: "VARCHAR(30)"; nonull]
last_name string [sql_type: "VARCHAR(30)"; nonull]
creci string [sql_type: "VARCHAR(8)"; nonull]
cnpj string [sql_type: "VARCHAR(15)"]
cpf string [sql_type: "VARCHAR(12)"]
phone string [sql_type: "VARCHAR(15)"; nonull]
real_state []RealState [fkey: 'id']
}
mut db := pg.connect(host: pg_host, user: pg_user, password: pg_pass, dbname: pg_db)!
defer {
db.close()
}
dump(sql db {
select from Realtor
}!)
Expected Behavior
something like...
[./src/main.v:37] ast.SqlExpr: [Realtor{
id: 'ffce0e60-084d-49c0-9e19-a272f257b1a4',
first_name: 'asdsd',
last_name: 'qweqwe',
creci: '4312',
cnpj: '',
cpf: '',
phone: '1241233',
real_state: '1'
}]
Current Behavior
V panic: as cast: cannot cast `unknown` to `v.ast.InfixExpr`
v hash: 12dd6e8
/tmp/v_1000/v2.2271908984048564447.tmp.c:20702: at _v_panic: Backtrace
/tmp/v_1000/v2.2271908984048564447.tmp.c:21209: by __as_cast
/tmp/v_1000/v2.2271908984048564447.tmp.c:11102: by v__gen__c__Gen_write_orm_select
/tmp/v_1000/v2.2271908984048564447.tmp.c:11145: by v__gen__c__Gen_write_orm_select
/tmp/v_1000/v2.2271908984048564447.tmp.c:10133: by v__gen__c__Gen_sql_select_expr
/tmp/v_1000/v2.2271908984048564447.tmp.c:63183: by v__gen__c__Gen_expr
/tmp/v_1000/v2.2271908984048564447.tmp.c:3111: by v__gen__c__Gen_dump_expr
/tmp/v_1000/v2.2271908984048564447.tmp.c:62978: by v__gen__c__Gen_expr
/tmp/v_1000/v2.2271908984048564447.tmp.c:61844: by v__gen__c__Gen_stmt
/tmp/v_1000/v2.2271908984048564447.tmp.c:61676: by v__gen__c__Gen_stmts_with_tmp_var
/tmp/v_1000/v2.2271908984048564447.tmp.c:61564: by v__gen__c__Gen_stmts
/tmp/v_1000/v2.2271908984048564447.tmp.c:3822: by v__gen__c__Gen_gen_fn_decl
/tmp/v_1000/v2.2271908984048564447.tmp.c:3509: by v__gen__c__Gen_fn_decl
/tmp/v_1000/v2.2271908984048564447.tmp.c:61856: by v__gen__c__Gen_stmt
/tmp/v_1000/v2.2271908984048564447.tmp.c:61676: by v__gen__c__Gen_stmts_with_tmp_var
/tmp/v_1000/v2.2271908984048564447.tmp.c:61564: by v__gen__c__Gen_stmts
/tmp/v_1000/v2.2271908984048564447.tmp.c:60494: by v__gen__c__Gen_gen_file
/tmp/v_1000/v2.2271908984048564447.tmp.c:60437: by v__gen__c__cgen_process_one_file_cb
/tmp/v_1000/v2.2271908984048564447.tmp.c:43543: by sync__pool__process_in_thread
/tmp/v_1000/v2.2271908984048564447.tmp.c:10971: by sync__pool__process_in_thread_thread_wrapper
7f8040bd7b43 : by ???
Possible Solution
???
Additional Information/Context
I already tried to do address Address [fkey: 'id'] because I thought it was like this and I also tried: address []Address [fkey: 'id'] which one is correct?
V version
V 0.4.1 12dd6e8
Environment details (OS name and version, etc.)
V full version: V 0.4.1 45e6e7d.12dd6e8
OS: linux, Ubuntu 22.04.3 LTS (WSL 2)
Processor: 8 cpus, 64bit, little endian, 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
getwd: /mnt/c/Users/AndreLuiz/Documents/SourceApps/QRImovel/QRIMovel-backend
vexe: /home/andre_luiz/system/v/v
vexe mtime: 2023-09-09 23:52:49
vroot: OK, value: /home/andre_luiz/system/v
VMODULES: OK, value: /home/andre_luiz/.vmodules
VTMP: OK, value: /tmp/v_1000
Git version: git version 2.34.1
Git vroot status: weekly.2023.33-138-g12dd6e8b (4 commit(s) behind V master)
.git/config present: true
CC version: cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
thirdparty/tcc status: Error: fatal: detected dubious ownership in repository at '/home/andre_luiz/system/v/thirdparty/tcc'
To add an exception for this directory, call:
git config --global --add safe.directory /home/andre_luiz/system/v/thirdparty/tcc
Error: fatal: detected dubious ownership in repository at '/home/andre_luiz/system/v/thirdparty/tcc'
To add an exception for this directory, call:
git config --global --add safe.directory /home/andre_luiz/system/v/thirdparty/tcc
Describe the bug
ORM cannot handle nested foreign keys, example:
Reproduction Steps
Expected Behavior
something like...
Current Behavior
Possible Solution
???
Additional Information/Context
I already tried to do
address Address [fkey: 'id']because I thought it was like this and I also tried:address []Address [fkey: 'id']which one is correct?V version
V 0.4.1 12dd6e8
Environment details (OS name and version, etc.)
V full version: V 0.4.1 45e6e7d.12dd6e8
OS: linux, Ubuntu 22.04.3 LTS (WSL 2)
Processor: 8 cpus, 64bit, little endian, 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
getwd: /mnt/c/Users/AndreLuiz/Documents/SourceApps/QRImovel/QRIMovel-backend
vexe: /home/andre_luiz/system/v/v
vexe mtime: 2023-09-09 23:52:49
vroot: OK, value: /home/andre_luiz/system/v
VMODULES: OK, value: /home/andre_luiz/.vmodules
VTMP: OK, value: /tmp/v_1000
Git version: git version 2.34.1
Git vroot status: weekly.2023.33-138-g12dd6e8b (4 commit(s) behind V master)
.git/config present: true
CC version: cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
thirdparty/tcc status: Error: fatal: detected dubious ownership in repository at '/home/andre_luiz/system/v/thirdparty/tcc'
To add an exception for this directory, call:
Error: fatal: detected dubious ownership in repository at '/home/andre_luiz/system/v/thirdparty/tcc'
To add an exception for this directory, call: