Grails 域多重继承和多个关系从无效状态移除

Grails 域多重继承和多个关系从无效状态移除,grails,gorm,Grails,Gorm,由于内容管理业务,我准备了一些复杂的模型结构 我的主要内容模型如下代码所示 class CmsContent implements Comparable<CmsContent>, Taggable, Serializable { Set<CmsContent> contents static hasMany = [contents:CmsContent] } 在控制器端,当将图像添加到菜单时,它可以完美地工作 de

由于内容管理业务,我准备了一些复杂的模型结构

我的主要内容模型如下代码所示

    class CmsContent implements Comparable<CmsContent>, Taggable, Serializable {
          Set<CmsContent> contents
          static hasMany = [contents:CmsContent]
    }
在控制器端,当将图像添加到菜单时,它可以完美地工作

def addContent(){

        Menu menuInstance = Menu.get(params.id)
        if (menuInstance == null) {
            notFound()
            return
        }

        CmsContent content = CmsContent.get(params.contentId)
        if (content == null) {
            notFound()
            return
        }

        menuInstance.addToContents(content)
        menuInstance.save(flush: true)

        request.withFormat {

            '*'{
                def result =[:]  ;
                result.status ='success';
                render result as JSON
            }
        }
    }


def removeContent(){

    Menu menuInstance = Menu.get(params.id)
    if (menuInstance == null) {
        notFound()
        return
    }

    long id = Long.valueOf(params.contentId)
    CmsContent content = cmsContent.contents.find { it.id == id }
    if (content == null) {
        notFound()
        return
    }

    menuInstance.removeFromContents(content)
    menuInstance.save(flush: true)

    request.withFormat {
        '*'{
            def result =[:]  ;
            result.status ='success';
            render result as JSON
        }
    }

}
但当我试图删除时,遇到了以下异常

Cannot get property 'name' on null object. Stacktrace follows:
Message: Cannot get property 'name' on null object
if (prop.bidirectional) {
   if (prop.manyToMany) {
        String name = prop.otherSide.name
        arg[name]?.remove(delegate)
   } else {
        arg[prop.otherSide.name] = null
   }
}
我在域ClassGrailsPlugin中找到了grails代码。 我意识到addTo方法和第368行检查prop.otherSide属性

if (prop.bidirectional && prop.otherSide) {
}
不幸的是,removive方法没有检查prop.otherSide属性,因此name字段引发异常

Cannot get property 'name' on null object. Stacktrace follows:
Message: Cannot get property 'name' on null object
if (prop.bidirectional) {
   if (prop.manyToMany) {
        String name = prop.otherSide.name
        arg[name]?.remove(delegate)
   } else {
        arg[prop.otherSide.name] = null
   }
}

你觉得怎么样?你同意我的观点吗?

我分叉了grails core,并对grails插件域类模块进行了必要的修复。只是构建了它并复制到lib目录中。目前,一切似乎都很好。我还将更正推送到github。仅供参考。我的请求已被Graemorocher接受。他刚刚将修复程序与2.3.x版本合并。