【发布时间】:2017-07-23 14:19:43
【问题描述】:
我使用 Grails 构建了这些域:
class Book {
String title
}
class Author {
String name
static hasMany = [books: Book]
}
def book1 = new Book(title: "The Shining")
def author1 = new Author(name: "Stephen King")
author1.addToBooks(book1)
如果尝试删除author1:
author1.books.clear()
author1.delete flush:true
我收到此错误:
消息 null 由 参照完整性约束违规:“FKQG8TLCGMC6WKG6ILECFOXSLVS:PUBLIC.PROJECT_BOOK FOREIGN KEY(BOOK_AUTHOR_ID) REFERENCES PUBLIC.PROJECT_AUTHOR(ID) (1)"; SQL 声明:从 id=? 的 project_column 中删除和版本=? [23503-195]
我想删除作者而不删除书籍。
【问题讨论】:
-
你已经模拟了一个作者有很多书,所以所有的书都绑定到作者。如果删除作者,书籍将属于?因为它在那个时候是损坏的数据,所以它是正确的
-
如果我删除作者,书籍必须继续存在
-
我没有使用belongto
标签: grails grails-orm grails-domain-class