(Quick Reference)

hasMany

目的
Purpose

Defines a one-to-many association between two classes.

使用例
Examples

class Author {

String name

static hasMany = [books: Book] }

In this example we define a one-to-many relationship between the Author and Book classes (one Author has many Books)

詳細
Description

By default GORM will create a property of type java.util.Set using the key inside the definition of the hasMany map. For example consider this definition:

static hasMany = [books: Book]

Here a property of type java.util.Set called books will be created within the defining class. These can then be iterated over and manipulated:

def a = Author.get(1)
for (book in a.books) { println book.title }