简单的级联关系
class Author {
String name
static hasMany = [book:Book]
static constraints = {
}
}
class Book {
String title
static belongsTo = [author: Author]
static constraints = {
}
static mapping = {
author cascade: ‘all‘
}
}
// 自动创建出来的表结构
CREATE TABLE
author
(
id BIGINT NOT NULL,
version BIGINT NOT NULL,
name CHARACTER VARYING(255) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE
book
(
id BIGINT NOT NULL,
version BIGINT NOT NULL,
title CHARACTER VARYING(255) NOT NULL,
author_id BIGINT NOT NULL,
PRIMARY KEY (id),
CONSTRAINT fkklnrv3weler2ftkweewlky958 FOREIGN KEY (author_id) REFERENCES "author" ("id")
);
http://docs.grails.org/3.1.1/ref/Domain%20Classes/belongsTo.html
http://grails.1312388.n4.nabble.com/How-to-cascade-delete-belongsTo-isn-t-working-td3329469.html
原文:https://www.cnblogs.com/duchaoqun/p/12851515.html