0

grails で 3 つのドメインからリストを取得しようとしています (通常のプログラミング言語での内部結合のようなもの)

ここに私のドメインがあります

class Category{
    Integer id
    String name  
}
class Tag{
    Integer id
    String name  
}
class Content{
    Integer id
    Category category
    Tag tag
    String text
}
//--------
def contentInstance = Content.findAllWhere(id:id.toInteger())

リスト内の Content.text、Category.name、Tag.name を View に表示できるようにしたい ありがとう

4

1 に答える 1

2

条件クエリ API を使用して、カスタム列を選択できます。次のように使用できます。

Content.withCriteria {
projections {
  property('text')
    category {
      property('name')
    }
    tag{
      property('name')
    }
  }       
}

または、次のようなエイリアスを作成できます。

Content.withCriteria {
createAlias("category","categoryAlias")
createAlias("tag","tagAlias")
projections {
  property('text')
  property('categoryAlias.name')
  property('tagAlias.name')

} 
and{
    eq('category.id','categoryAlias.id')
    eq('tag.id','tagAlias.id')
  }    
}

あなたがアイデアを得たことを願っています...

于 2013-05-13T06:58:55.567 に答える