我现在遇到问题,我有2个域类,即医生和病人,他们有1:m的关系.这是我的班级医生的代码
class Doctor {
String name
String specialization
def doctorService
static hasMany = [patients: Patient]
static belongsTo = [hospital: Hospital]
static constraints = {
name(blank:false)
specialization(blank:false)
patients(nullable:true)
hospital(nullable:false)
}
String toString(){
"Doctor ${name} "
}
}
Run Code Online (Sandbox Code Playgroud)
- >这是我的类患者代码:
class Patient {
String name
String ailment
int age
Date dateAdmit, dateDischarge
static belongsTo = [doctor: Doctor, hospital: Hospital]
static constraints = {
name(blank:false, maxSize:100)
ailment(blank:false)
age(size:1..200)
dateAdmit(nullable:true)
dateDischarge(nullable:true)
hospital(nullable:false)
doctor(nullable:false, validator:{val, obj -> val.hospital == obj.hospital})
}
String toString(){
"${name} "
}
}
Run Code Online (Sandbox Code Playgroud)
- >我想删除一个医生谁没有一个病人使用的executeUpdate() .我可以选择没有患者的医生使用这样的动态查找器.
_
def d = Doctor.findAll("from Doctor as d where not exists" +
"(from Patient as p where p.doctor = d)")
Run Code Online (Sandbox Code Playgroud)
_
似乎该语法在executeUpdate()中不起作用,我只是grails中的新手.请帮帮我..谢谢......
Bur*_*ith 10
用这个:
Doctor.executeUpdate('delete from Doctor d where d.patients is empty')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3711 次 |
最近记录: |