grails/gorm多列唯一约束冲突

grails/gorm多列唯一约束冲突,grails,gorm,Grails,Gorm,我已经在下面列出了我的域名。我试图在列上指定一个唯一约束,该约束将根据另一列的值使该列唯一,并且在父域中唯一 public enum PostStatus { PUBLISHED, PENDING_REVIEW, DRAFT, TRASH } public enum PostType { INTRO, FUTURE, FAMILY } class Post { String content PostType pos

我已经在下面列出了我的域名。我试图在列上指定一个唯一约束,该约束将根据另一列的值使该列唯一,并且在父域中唯一

public enum PostStatus {
    PUBLISHED,
    PENDING_REVIEW,
    DRAFT,
    TRASH
}

public enum PostType {
    INTRO,
    FUTURE,
    FAMILY
}


class Post {


    String content
    PostType postType
    PostStatus postStatus
    Date dateCreated
    Date lastUpdated
    static belongsTo = [basicProfile:BasicProfile]

    static constraints = {
        content(blank:true, nullable:true, maxSize:5000)
        postType(blank:false, nullable:false)
        postStatus(blank:false, nullable:false, unique:'postType') //status must be unique within each postType, and within the parent.
    }
    static mapping = {
        content sqlType:'text'
    }
}

class Profile {
    static hasMany = [
            post:Post
    ]
}
现在postStatus在postType中是唯一的,但它将唯一约束应用于Post表。因此,表允许每个postType有一个postStatus,然后发生唯一的约束冲突。我需要的是每个配置文件的每个postType都有一个唯一的postStatus

post表格插入示例: 良好记录#1: 个人资料编号:1 后置状态:草稿 post_类型:简介

良好记录#2: 个人资料编号:1 发布状态:已发布 post_类型:简介

良好记录#3: 个人资料编号:1 后置状态:草稿 岗位类型:未来

坏记录#4违反了记录1的唯一约束,即使它用于不同的配置文件id。 个人资料编号:2 后置状态:草稿 post_类型:简介

帖子属于一个概要文件,那么我如何定义约束以使每个概要文件都是唯一的呢?基本上,我试图得到一个复合唯一键:


profile.id+postType+postStatus

您是否尝试了中描述的最后一个示例

e、 g:postStatus(空白:false,可空:false,唯一:['postType','basicProfile'])