0

我有一个域类 People,它有多个汽车和房屋:

def People {
    SortedSet<Car> cars = new TreeSet<Car>()
    SortedSet<House> houses = new TreeSet<House>()
}

def Car {
    Long id
}

def House {
    Long id
}

在 grails 中,我想找到拥有 id = 1 的汽车和 id = 1 的房子的人。

我如何有效地实现这一目标?我已经尝试过了,但它不起作用:

People.withCriteria {
    cars {
        inList('id', 1L)
    }
    houses {
        inList('id', 1L)
    }
}

这也不是,因为它返回多个相似的对象:

People.withCriteria {
    createAlias('cars', c)
    createAlias('houses', h)

    inList('c.id', 1L)
    inList('h.id', 1L)
}

有人会在这里伸出援手吗?谢谢!

4

0 回答 0