For (1) and (2), I don't know if there is a way to do what you want with just one query for criteria, but an alternative way just seems to be simpler and more natural. For (1):
def car = Car.get(carId) def owners = car.owner?.name
For (2)
def person = Person.get(personId) def cars = person.cars*.name
Oh (3), this is a design issue here. Your current domain design does not reflect the rule you are describing, so it will be difficult to maintain this restriction. You can map the PersonOrganization table and make the subsidiary an impassable property . For example:
class Organization { int id String name Organization parent static transients = ['children'] ... Boolean children() { def children = Organization.createCriteria().list() { eq ('parent', this) } return children } }
After that, you can use a tracking function such as getAllAncestors () to determine the entire parent hierarchy of the organization, see it in the list of personal organizations. This is not the best way, but it is possible.
Hoàng long
source share