Grails update instead of delete

随声附和 提交于 2019-12-03 03:38:27

You'll have to ovveride the delete and list methods of all your domain classes. Add code like this to your Bootstrap

class BootStrap {

  def grailsApplication

  def init = { servletContext ->

  for (dc in grailsApplication.domainClasses) {

     dc.clazz.exists(-1);  //to register meta class

     def gormSave = dc.clazz.metaClass.getMetaMethod('save');         
     dc.clazz.metaClass.delete = {  ->
        delegate.deleted = true
        gormSave.invoke delegate
     }

     dc.clazz.metaClass.delete = { Map args  ->
        delegate.deleted = true
        gormSave.invoke(delegate, args)
     }

     dc.clazz.metaClass.static.list = {  ->
        def crit = delegate.createCriteria();
        def list = crit.list{
          eq('deleted', false)
        }
        return list;
     }



  }
}

   def destroy = {}
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!