grails-domain-class

getting grails 2.0.0M1 config info in domain object, and static scope?

*爱你&永不变心* 提交于 2019-11-29 21:12:45
问题 How do I get to the Config.groovy information from a domain object, or from a static scope? I'm using ConfigurationHolder.config.* now, but that and ApplicationHolder are deprecated so I'd like to 'do it right' ... but the grailsApplication object isn't available in a DO/static scope. 回答1: I'd add the grailsApplication to the metaclass of domain classes - this is something I'm thinking about doing for 2.0 final. For now, put it in BootStrap.groovy , e.g. class BootStrap { def

Grails domain class: unique constraint for multiple columns

偶尔善良 提交于 2019-11-28 20:03:48
Suppose a simple Grails domain class: class Account { String countryId; String userName; String password; static constraints = { ...???... } } It is required that user names are unique for a particular countryId , thus there must be a unique contraint on two columns. How to express this in the constraints definition? userName(unique: ['countryId']) You can include as many other properties in the array that make up the other properties that must be considered in the "unique" constraint on the username. So, for example if you wanted to make userName unique within a countryId and provinceId it

Grails domain beforeInsert / beforeUpdate

不想你离开。 提交于 2019-11-28 06:01:35
问题 I want to save my domain class to the database without specifying the createdUser or createdDate . I’ve created an object called AuditingInfo and embedded it in the main Person domain class like this: AuditingInfo.groovy : class AuditingInfo { static constraints = { createdUser (nullable : true) updatedUser (nullable : true) createdDate(nullable : true) updatedDate(nullable : true) } static mapping = { columns { createdUsercolumn: 'T_CREATED_USER' updatedUsercolumn: 'T_UPDATED_USER'

Grails: find domain class by name

馋奶兔 提交于 2019-11-27 20:10:07
I want to allow users to traverse the domain classes and print out dumps of stuff. My frist problem: assuming the following works just fine: //this works class EasyStuffController{ def quickStuff = { def findAThing = MyDomainClass.findByStuff(params.stuff) [foundThing:findAThing] } } What is the proper way to write what I am trying to say below: //this doesn't class EasyStuffController{ servletContext -> def quickStuff = { def classNameString = "MyDomainClass" //or params.whichOne something like that def domainHandle = grailsApplication.domainClasses.findByFullName(classNameString) //no such

Grails domain class: unique constraint for multiple columns

扶醉桌前 提交于 2019-11-27 12:40:34
问题 Suppose a simple Grails domain class: class Account { String countryId; String userName; String password; static constraints = { ...???... } } It is required that user names are unique for a particular countryId , thus there must be a unique contraint on two columns. How to express this in the constraints definition? 回答1: userName(unique: ['countryId']) You can include as many other properties in the array that make up the other properties that must be considered in the "unique" constraint on

How to adjust constraints / DB mapping for Map within grails domain class

ε祈祈猫儿з 提交于 2019-11-27 07:02:39
问题 Following grails domain class: class MyClass { Map myMap } Now for myMap, grails automatically creates a new table for the elements in the map. However if I add elements which are too long (e.g. 1024 characters), I get a DB error. Can I somehow tell grails to make the respective column in myMap's table big enough to allow for larger Strings, or do I have to do this manually in the DB? I already tried static constraints = { myMap(maxSize:1024) } which doesn't work (as expected because maxSize

Grails: find domain class by name

a 夏天 提交于 2019-11-26 20:13:13
问题 I want to allow users to traverse the domain classes and print out dumps of stuff. My frist problem: assuming the following works just fine: //this works class EasyStuffController{ def quickStuff = { def findAThing = MyDomainClass.findByStuff(params.stuff) [foundThing:findAThing] } } What is the proper way to write what I am trying to say below: //this doesn't class EasyStuffController{ servletContext -> def quickStuff = { def classNameString = "MyDomainClass" //or params.whichOne something

Grails get child domain objects

别等时光非礼了梦想. 提交于 2019-11-26 13:03:09
问题 I have two domain classes one is parent and other one is child and i have a hasMany relationship between them. Parent class has many childs and child class belongs to parent class. And here is coding example. class Parent{ String name static hasMany = [childs:Child] static constraints = { } } class Child{ String name static belongsTo = [parent:Parent] static constraints={} } Problem is as soon as I get the parent object the child objects associated with parent class were also fetched. But