【问题标题】:Grails GORM searching for list items that match another listGrails GORM 搜索与另一个列表匹配的列表项
【发布时间】:2014-06-07 23:28:29
【问题描述】:

我有三个对象:

老师, 孩子, 家长

Teacher.students 是一个子对象列表

Parent.children 也是一个子对象列表

我想找到所有教某位家长孩子的老师。

我试过了,但它只能找到一个孩子的老师。如果父母有多个孩子,我需要这样做。

def teachers = Teacher.withCriteria{ 
    students { 
        inList("id", parent.children.first().id ) 
    } 
}

【问题讨论】:

    标签: grails groovy grails-orm


    【解决方案1】:

    你只是在获取第一个 id;您需要使用 all 孩子的 id,您可以使用传播 (*) 运算符获得。另外,根据docs,方法是in,而不是inList作为标准,但我可能会遗漏一些关于版本等的东西:

    in("id", parent.children*.id)
    

    【讨论】:

      猜你喜欢
      • 2021-07-12
      • 2010-10-28
      • 1970-01-01
      • 2023-02-17
      • 2018-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多