次のドメインクラスがあるとします。
class Book {
String title
String author
byte[] largeCoverArtImage
}
表示する必要のないリストビューがありますがlargeCoverArtImage
、GORM基準を使用して次のSQLクエリを実行するにはどうすればよいですか?
select title, author from Book
次のドメインクラスがあるとします。
class Book {
String title
String author
byte[] largeCoverArtImage
}
表示する必要のないリストビューがありますがlargeCoverArtImage
、GORM基準を使用して次のSQLクエリを実行するにはどうすればよいですか?
select title, author from Book
executeQueryを使用して、個々の列を選択するHQLクエリを実行できます。
def titlesAndAuthors = Book.executeQuery('select title, author from Book')
これにより、Object[]のリストが返されます。
for (row in titlesAndAuthors) {
String title = row[0]
String author = row[1]
...
}
Grails(1.3.7バージョンでテスト済み)では、次のように書くことができます。
def titlesAndAuthors = Book.withCriteria {
projections {
property 'title', 'title'
property 'author', 'author'
}
}
そして、上記の例のようにObject[]のリストを取得します。