我有以下 Grails 类和关系:
class Book {
static hasMany = [articles: Article]
}
class Article {
static belongsTo = [book: Book]
}
我可以执行以下操作来设置正确的关系吗?
def book = // some book instance
def article = new Article()
article.book = book
article.save()
前者和下面一样吗?
def book = // some book instance
def article = new Article()
book.addToArticles(article)
book.save()