我通过互联网浏览,但仍未找到问题的答案。应该很容易:
class Parent {
String name
Child child
}
当我有一个 child 对象时,如何获得它的 parent ?
喜欢:
def Parent = Parent.findByChild(child)
我怎样才能让它的 child 得到一个父对象?
谢谢
最佳答案
你去哪了
这些是 Realm 类吗?如果是这样,则可以通过has_many和belongs_to将它们连接:
class Parent {
String name
List children
static has_many = [ children: Child ]
}
class Child {
static belongs_to = [ parent: Parent ]
}
那你就可以写
child.parent
关于grails - Grails按 child 找 parent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7923510/