gpt4 book ai didi

grails - 在 grails 版本 3.3.11 中获取验证错误,但在 grails 2.0.1 中没有

转载 作者:行者123 更新时间:2023-12-02 13:47:50 25 4
gpt4 key购买 nike

在 grails 版本 3.3.11 中获取验证错误,但在 grails 2.0.1 中没有

请在下面找到示例代码

//**Domain classes**

class Booking {
String bookingtype;
Patient patient
static constraints = {
}
}

class ContactDetails {
String city
String state
String postCode

static constraints = {
city blank: false
postCode blank: false
state blank: false
}
}

class Patient {
String name;
ContactDetails contactDetails

static embedded = ['contactDetails']

static constraints = {
contactDetails nullable: true
}
}


//**Controller**
class NewHomeController {

def index() { }

def createContactDetails(){
def patient=new Patient()
patient.name="Name"
patient.contactDetails=new ContactDetails()
patient.save(flush: true,deepValidate:false)
def booking=new Booking()
booking.bookingtype="Online"
booking.patient=patient;
booking.save(flush: true,failOnError: true)
render "Done"
}
}

如果我在 grails 2.0.1 中运行上面的代码,它运行良好,但在 grails 3.3.11 中却不行。如果我将对象坚持为 booking.save(flush: true,deepValidate:false) 那么它工作正常,因为它将忽略验证子关联。

从 grails 2 到 grails 3 自动创建表没有区别

**Grails 3**
--------
CREATE TABLE `patient` (
id` bigint(20) NOT NULL AUTO_INCREMENT,
`version` bigint(20) NOT NULL,
`name` varchar(255) NOT NULL,
`contact_details_city` varchar(255) DEFAULT NULL,
`contact_details_country` varchar(11) DEFAULT NULL,
`contact_details_state` varchar(255) DEFAULT NULL,
`contact_details_post_code` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8


CREATE TABLE `contact_details` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`version` bigint(20) NOT NULL,
`city` varchar(255) NOT NULL,
`country` varchar(11) NOT NULL,
`state` varchar(255) NOT NULL,
`post_code` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8


CREATE TABLE `booking` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`version` bigint(20) NOT NULL,
`patient_id` bigint(20) NOT NULL,
`bookingtype` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
KEY `FK1o2fk91av3dkwlxpexo94lcbg` (`patient_id`),
CONSTRAINT `FK1o2fk91av3dkwlxpexo94lcbg` FOREIGN KEY (`patient_id`) REFERENCES `patient` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8



**Grails 2**
---------


CREATE TABLE `patient` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`version` bigint(20) NOT NULL,
`contact_details_city` varchar(255) DEFAULT NULL,
`contact_details_country` varchar(11) DEFAULT NULL,
`contact_details_post_code` varchar(255) DEFAULT NULL,
`contact_details_state` varchar(255) DEFAULT NULL,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8

CREATE TABLE `contact_details` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`version` bigint(20) NOT NULL,
`city` varchar(255) NOT NULL,
`country` varchar(11) NOT NULL,
`post_code` varchar(255) NOT NULL,
`state` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8


CREATE TABLE `booking` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`version` bigint(20) NOT NULL,
`bookingtype` va rchar(255) NOT NULL,
`patient_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `FK3DB0859F465DE24` (`patient_id`),
CONSTRAINT `FK3DB0859F465DE24` FOREIGN KEY (`patient_id`) REFERENCES `patient` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8

我得到的验证异常是

Caused by: grails.validation.ValidationException: Validation Error(s) occurred during save():
- Field error in object 'domain_constraint_verification_3_3_11.Booking' on field 'patient.contactDetails.city': rejected value [null]; codes [domain_constraint_verification_3_3_11.ContactDetails.city.nullable.error.domain_constraint_verification_3_3_11.Booking.patient.contactDetails.city,domain_constraint_verification_3_3_11.ContactDetails.city.nullable.error.patient.contactDetails.city,domain_constraint_verification_3_3_11.ContactDetails.city.nullable.error.city,domain_constraint_verification_3_3_11.ContactDetails.city.nullable.error.java.lang.String,domain_constraint_verification_3_3_11.ContactDetails.city.nullable.error,contactDetails.city.nullable.error.domain_constraint_verification_3_3_11.Booking.patient.contactDetails.city,contactDetails.city.nullable.error.patient.contactDetails.city,contactDetails.city.nullable.error.city,contactDetails.city.nullable.error.java.lang.String,contactDetails.city.nullable.error,domain_constraint_verification_3_3_11.ContactDetails.city.nullable.domain_constraint_verification_3_3_11.Booking.patient.contactDetails.city,domain_constraint_verification_3_3_11.ContactDetails.city.nullable.patient.contactDetails.city,domain_constraint_verification_3_3_11.ContactDetails.city.nullable.city,domain_constraint_verification_3_3_11.ContactDetails.city.nullable.java.lang.String,domain_constraint_verification_3_3_11.ContactDetails.city.nullable,contactDetails.city.nullable.domain_constraint_verification_3_3_11.Booking.patient.contactDetails.city,contactDetails.city.nullable.patient.contactDetails.city,contactDetails.city.nullable.city,contactDetails.city.nullable.java.lang.String,contactDetails.city.nullable,nullable.domain_constraint_verification_3_3_11.Booking.patient.contactDetails.city,nullable.patient.contactDetails.city,nullable.city,nullable.java.lang.String,nullable]; arguments [city,class domain_constraint_verification_3_3_11.ContactDetails]; default message [Property [{0}] of class [{1}] cannot be null]
- Field error in object 'domain_constraint_verification_3_3_11.Booking' on field 'patient.contactDetails.state': rejected value [null]; codes [domain_constraint_verification_3_3_11.ContactDetails.state.nullable.error.domain_constraint_verification_3_3_11.Booking.patient.contactDetails.state,domain_constraint_verification_3_3_11.ContactDetails.state.nullable.error.patient.contactDetails.state,domain_constraint_verification_3_3_11.ContactDetails.state.nullable.error.state,domain_constraint_verification_3_3_11.ContactDetails.state.nullable.error.java.lang.String,domain_constraint_verification_3_3_11.ContactDetails.state.nullable.error,contactDetails.state.nullable.error.domain_constraint_verification_3_3_11.Booking.patient.contactDetails.state,contactDetails.state.nullable.error.patient.contactDetails.state,contactDetails.state.nullable.error.state,contactDetails.state.nullable.error.java.lang.String,contactDetails.state.nullable.error,domain_constraint_verification_3_3_11.ContactDetails.state.nullable.domain_constraint_verification_3_3_11.Booking.patient.contactDetails.state,domain_constraint_verification_3_3_11.ContactDetails.state.nullable.patient.contactDetails.state,domain_constraint_verification_3_3_11.ContactDetails.state.nullable.state,domain_constraint_verification_3_3_11.ContactDetails.state.nullable.java.lang.String,domain_constraint_verification_3_3_11.ContactDetails.state.nullable,contactDetails.state.nullable.domain_constraint_verification_3_3_11.Booking.patient.contactDetails.state,contactDetails.state.nullable.patient.contactDetails.state,contactDetails.state.nullable.state,contactDetails.state.nullable.java.lang.String,contactDetails.state.nullable,nullable.domain_constraint_verification_3_3_11.Booking.patient.contactDetails.state,nullable.patient.contactDetails.state,nullable.state,nullable.java.lang.String,nullable]; arguments [state,class domain_constraint_verification_3_3_11.ContactDetails]; default message [Property [{0}] of class [{1}] cannot be null]
- Field error in object 'domain_constraint_verification_3_3_11.Booking' on field 'patient.contactDetails.postCode': rejected value [null]; codes [domain_constraint_verification_3_3_11.ContactDetails.postCode.nullable.error.domain_constraint_verification_3_3_11.Booking.patient.contactDetails.postCode,domain_constraint_verification_3_3_11.ContactDetails.postCode.nullable.error.patient.contactDetails.postCode,domain_constraint_verification_3_3_11.ContactDetails.postCode.nullable.error.postCode,domain_constraint_verification_3_3_11.ContactDetails.postCode.nullable.error.java.lang.String,domain_constraint_verification_3_3_11.ContactDetails.postCode.nullable.error,contactDetails.postCode.nullable.error.domain_constraint_verification_3_3_11.Booking.patient.contactDetails.postCode,contactDetails.postCode.nullable.error.patient.contactDetails.postCode,contactDetails.postCode.nullable.error.postCode,contactDetails.postCode.nullable.error.java.lang.String,contactDetails.postCode.nullable.error,domain_constraint_verification_3_3_11.ContactDetails.postCode.nullable.domain_constraint_verification_3_3_11.Booking.patient.contactDetails.postCode,domain_constraint_verification_3_3_11.ContactDetails.postCode.nullable.patient.contactDetails.postCode,domain_constraint_verification_3_3_11.ContactDetails.postCode.nullable.postCode,domain_constraint_verification_3_3_11.ContactDetails.postCode.nullable.java.lang.String,domain_constraint_verification_3_3_11.ContactDetails.postCode.nullable,contactDetails.postCode.nullable.domain_constraint_verification_3_3_11.Booking.patient.contactDetails.postCode,contactDetails.postCode.nullable.patient.contactDetails.postCode,contactDetails.postCode.nullable.postCode,contactDetails.postCode.nullable.java.lang.String,contactDetails.postCode.nullable,nullable.domain_constraint_verification_3_3_11.Booking.patient.contactDetails.postCode,nullable.patient.contactDetails.postCode,nullable.postCode,nullable.java.lang.String,nullable]; arguments [postCode,class domain_constraint_verification_3_3_11.ContactDetails]; default message [Property [{0}] of class [{1}] cannot be null]

在最新的 grails 文档中没有找到与验证相关的任何更新。我错过了什么吗?

最佳答案

我通过禁用深度验证来解决这个问题,因为在较新版本的 grails 中有一些深度验证更新。

关于grails - 在 grails 版本 3.3.11 中获取验证错误,但在 grails 2.0.1 中没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62521141/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com