Modify Id generation for a Grails Plugin

北战南征 提交于 2020-01-05 13:49:25

问题


I am using a plugin for Grails - the Amazon S3 plugin - and the domain object provided by the plugin doesn't specify the Id Generator. I am using Postgresql and require the id genrator to be identity.

I could copy the plugin in my plugins directory and mess with the domain object provided but that doesn't sound like a clean approach.Could I add the correct id generation at runtime? Or maybe there is a better way.


回答1:


If you are using 1.2, you could provide a default mapping for all your GORM classes, including generator.

grails.gorm.default.mapping = {
   id generator:'sequence'
}

See more in 1.2 release notes.




回答2:


I think you could copy just the S3Asset.groovy into src/groovy/. From memory, your class should override the one provided by the plugin. I've used this technique to tweak a couple of plugins until bugs were fixed. But I haven't tried it with domain classes only *GrailsPlugin.groovy files.

Also, Jean's suggestion above is a good one!

cheers

Lee



来源:https://stackoverflow.com/questions/2033807/modify-id-generation-for-a-grails-plugin

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