mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
orm: fix orm unique lists (#11198)
This commit is contained in:
parent
482eecbc13
commit
0d30667ab5
@ -67,7 +67,6 @@ fn sqlite3_array() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sql db {
|
sql db {
|
||||||
drop table Child
|
|
||||||
drop table Parent
|
drop table Parent
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +110,6 @@ fn mysql_array() {
|
|||||||
eprintln(parent)
|
eprintln(parent)
|
||||||
|
|
||||||
sql db {
|
sql db {
|
||||||
drop table Child
|
|
||||||
drop table Parent
|
drop table Parent
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +148,6 @@ fn psql_array() {
|
|||||||
eprintln(parent)
|
eprintln(parent)
|
||||||
|
|
||||||
sql db {
|
sql db {
|
||||||
drop table Child
|
|
||||||
drop table Parent
|
drop table Parent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,6 +298,7 @@ pub fn orm_table_gen(table string, para string, defaults bool, def_unique_len in
|
|||||||
mut is_skip := false
|
mut is_skip := false
|
||||||
mut unique_len := 0
|
mut unique_len := 0
|
||||||
// mut fkey := ''
|
// mut fkey := ''
|
||||||
|
mut field_name := sql_field_name(field)
|
||||||
for attr in field.attrs {
|
for attr in field.attrs {
|
||||||
match attr.name {
|
match attr.name {
|
||||||
'primary' {
|
'primary' {
|
||||||
@ -306,7 +307,7 @@ pub fn orm_table_gen(table string, para string, defaults bool, def_unique_len in
|
|||||||
'unique' {
|
'unique' {
|
||||||
if attr.arg != '' {
|
if attr.arg != '' {
|
||||||
if attr.kind == .string {
|
if attr.kind == .string {
|
||||||
unique[attr.arg] << field.name
|
unique[attr.arg] << field_name
|
||||||
continue
|
continue
|
||||||
} else if attr.kind == .number {
|
} else if attr.kind == .number {
|
||||||
unique_len = attr.arg.int()
|
unique_len = attr.arg.int()
|
||||||
@ -337,7 +338,6 @@ pub fn orm_table_gen(table string, para string, defaults bool, def_unique_len in
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
mut stmt := ''
|
mut stmt := ''
|
||||||
mut field_name := sql_field_name(field)
|
|
||||||
mut ctyp := sql_from_v(sql_field_type(field)) or {
|
mut ctyp := sql_from_v(sql_field_type(field)) or {
|
||||||
field_name = '${field_name}_id'
|
field_name = '${field_name}_id'
|
||||||
sql_from_v(7) ?
|
sql_from_v(7) ?
|
||||||
@ -353,7 +353,7 @@ pub fn orm_table_gen(table string, para string, defaults bool, def_unique_len in
|
|||||||
stmt += ' NOT NULL'
|
stmt += ' NOT NULL'
|
||||||
}
|
}
|
||||||
if is_unique {
|
if is_unique {
|
||||||
mut f := 'UNIQUE($para$field.name$para'
|
mut f := 'UNIQUE($para$field_name$para'
|
||||||
if ctyp == 'TEXT' && def_unique_len > 0 {
|
if ctyp == 'TEXT' && def_unique_len > 0 {
|
||||||
if unique_len > 0 {
|
if unique_len > 0 {
|
||||||
f += '($unique_len)'
|
f += '($unique_len)'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user