내가 저자와 책 사이의 많은 관계로 하나를 한 번 저자는 많은 책을 가지고 ..부모를 삭제하는 동안 Grails가 하위를 삭제하지 못하게하는 방법은 무엇입니까?
내가 가진이
Author.groovy
class Author {
String authorName;
String authorAddress;
String authorCNIC;
static hasMany = [books:Book]
static constraints = {
books(nullable: true)
}
}
Book.groovy
같은 도메인 클래스class Book {
String bookName;
String Isbn;
static belongsTo = [author:Author]
static constraints = {
author(nullable: true)
}
}
이 함수를 호출 할 때
def deleteauthor()
{
def id=params.id
Author author = Author.findById(id);
author.delete(flush: true)
render "Author Deleted"
}
저자 및 모든 하위 책을 삭제합니다.이 동작을 원하지 않습니다. 작성자와 책을 삭제할 수 없으며 메시지를 표시 할 수 없기 때문에 저자, 먼저 책을 삭제할 수 없습니다. 방법을 알려주십시오. 이 작업을 수행 ? 당신의 저자 모델에서
작성자를 찾아서 책 수가 0보다 작 으면 삭제하지 말고 오류 메시지를 발행하십시오. – railsdog
작가 책 수를 확인하는 방법은 무엇입니까? – Ahmad
'저자 작성자 = .get (id) if (author.books? .size()> 0) {렌더링 실패} return} author.delete (flush : true) render "작성자 삭제됨"은 방법입니다. 하지만 어쩌면 당신은'캐스케이드'를 볼 필요가있다 http://docs.grails.org/latest/ref/Database%20Mapping/cascade.html – Vahid