0

以下のように2つのドメインがある場合

class Author {
  static hasMany = [books: Book]
  String name
}

class Book {
  static belongsTo = [author: Author]
  String color
}

著者の複数の本を同時に追加するにはどうすればよいですか?

以下のように:

def book1 = new Book(color: "white")
def book2 = new Book(color: "black")
def books = []
books << book1
books << book2

def author = new Author(name: "John Doe").addToBooks(books).save()
4

1 に答える 1