We have an old application where the relationship is defined as below:
class Practice {
String name
static hasmany = [doctors:Doctor]
}
and
class Doctor {
String name
}
There is not a belongsTo
relationship defined in Doctor
as we do not want to cascade the delete of a doctor when Practice
is deleted. This is a very old code and do not want to change it.
Now according to the new functionality, the user should know which Practice
s the Doctor
is linked to while viewing the details of a Doctor
. Can anyone help me knowing which is the easiest way of achieving this without making changes to the domain object?
If variable doctor
contains the doctor you want to list practices from, you can get a list of Practice
objects having this doctor in their doctors relationship by issuing the following criteria query:
def practices = Practice.withCriteria {
doctors {
idEq(doctor.id)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With