1

I have three classes in my grails project. What is the proper grails domain definition

Class A {

 List<Resource> xResources
 List<Resource> yResources

 hasMany = [ xResources: Resource, yResources: Resource]
}

Class B {
  List<Resource> zResources
  hasMany = [ zResources: Resource]
}


Class Resource {

  String title
   .....
     ..

 belongsTo = [A, B]

}

The above definition fails because i have not mentioned the mappedBy in Class A. How that can be avoided. I want the Resource class to be generic. I don't want to restrict the Resource class only to the two classes, but i should allow it extend it to other. I also need to get the source reference from a Resource object. What should be proper GORM definition for this scenario.?

4

2 回答 2

0

请按照以下代码

Class A {
static hasMany = [ xResources: Resource, yResources: Resource]
}

Class B {

static hasMany = [ zResources: Resource]
}


Class Resource {

  String title
   .....
     ..

 static belongsTo = [a:A, b:B]

}
于 2013-03-06T03:06:28.247 回答
0

我在您的代码中看到 3 个主要问题:

  1. 属性xResources, yResources, zResources是双重定义的。只需删除重复的List<Resource> ...定义。

  2. hasMany并且前面belongsTo应该有一个static关键词。

  3. 我不确定belongsTo可以指向多个类。如果没有,只需将其删除。

于 2013-03-06T02:51:30.243 回答