{"id":1759,"date":"2010-09-24T16:45:16","date_gmt":"2010-09-24T11:15:16","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=1759"},"modified":"2016-12-19T15:06:11","modified_gmt":"2016-12-19T09:36:11","slug":"gorm-default-configurations-in-config-groovy","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/gorm-default-configurations-in-config-groovy\/","title":{"rendered":"Gorm default configurations in config.groovy"},"content":{"rendered":"<p>Recently while working on my new Project I have the requirement where each domains need to have dateCreated and lastUpdated fields. So rather than adding these fields to each of the domain class we added them to template. Now whenever we create a domain class these two fields are added to it automatically.<br \/>\nNext thing we want to add default constraints(nullable:true) to these two fields. We could do that in templates as well, I dont think anything wrong with this approach but my friend <a href=\"http:\/\/www.tothenew.com\/blog\/author\/himanshu\/\">HIMANSHU<\/a> told me a better way to do that by adding it to Config.groovy i,e;.<\/p>\n<pre lang=\"groovy\">\r\ngrails.gorm.default.constraints = {\r\n    'dateCreated'(display: false, nullable: true)\r\n    'lastUpdated'(display: false, nullable: true)\r\n}\r\n<\/pre>\n<p>In my project we are using Multi-tenant plugin as well and we want to have an index on tenantId field to make the retrieval faster. Again we could do that in the template as well but this time I go with the COC Rule of grails and tried the following code in Config.groovy<\/p>\n<pre lang=\"groovy\">\r\ngrails.gorm.default.mapping = {\r\n    'tenantId' column: 'tenant_id', index: 'tenant_id_idx'\r\n}\r\n<\/pre>\n<p>And it worked perfectly :). There are really so many good things about GRAILS that we need learn .<br \/>\n<\/p>\n<p>Hope it helps<br \/>\n<a href=\"http:\/\/www.tothenew.com\/blog\/author\/uday\/\">Uday Pratap Singh<\/a><br \/>\n<a href=\"mailto:uday@intelligrape.com\">uday@intelligrape.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently while working on my new Project I have the requirement where each domains need to have dateCreated and lastUpdated fields. So rather than adding these fields to each of the domain class we added them to template. Now whenever we create a domain class these two fields are added to it automatically. Next thing [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1},"categories":[7],"tags":[414,416,415,417,418],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1759"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=1759"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1759\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=1759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=1759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=1759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}