私はこの問題に関していくつかの質問があることを知っていますが、どれも私にとってはうまくいかないようです。Grails:hasMany associationにクエリする
class Tag {
String name
}
class SystemTag extends Tag {
// Will have additional properties here...just placeholder for now
}
class Location {
String name
Set<Tag> tags = []
static hasMany = [tags: Tag]
}
私は1個の以上のタグでタグ付けされたすべてのLocationオブジェクトを照会しようとしています:私はデータのことを検証してい
class LocationQueryTests {
@Test
public void testTagsQuery() {
def tag = new SystemTag(name: "My Locations").save(failOnError: true)
def locationNames = ["L1","L2","L3","L4","L5"]
def locations = []
locationNames.each {
locations << new Location(name: it).save(failOnError: true)
}
(2..4).each {
locations[it].tags << tag
locations[it].save(failOnError: true)
}
def results = Location.withCriteria {
tags {
'in'('name', [tag.name])
}
}
assertEquals(3, results.size()) // Returning 0 results
}
}
私は、次のドメインオブジェクトとGrailsのアプリを持っています作成中/正しく設定されています... 5ロケーションオブジェクトが作成され、最後の3つにタグが付けられました。
私は上記の質問に間違いはありません。私は本当にHQLから離れたいと思っています。私はそれがここで可能であるべきだと考えています。
'Location.count()'は5を返しますか?保存呼び出しに 'flush:true'を追加する必要があるかもしれません。 – doelleri