grails-constraints

Grails Scaffolding - define possible values for this property of a domain class

孤街醉人 提交于 2019-12-22 05:19:33
问题 I am new to Grails. I have a Person domain class as : class Person { String firstName String lastName String gender Date dateOfBirth } And wondering if I can define possible values for a property - say gender as {M, F, U} so that these three values will be listed in combo box when using dynamic scaffolding for Person controller. Here I just wanted to know if there is such feature in Grails framework? If such feature exists , then how can I use it? 回答1: From the documentation http://grails.org

How can I select multiple values from the inList constraint in Grails?

非 Y 不嫁゛ 提交于 2019-12-13 04:04:15
问题 I'm new to Grails and obviously missing something out.. but what?! I created a DomainClass An with a String property category. In the constraints I defined, that this category should have multiple (list) values: class An { String category static constraints = { category nullable: true, inList:["do", "me", "a", "favour"] } } In the view it is shown as a multiple select box: <g:select name="category" from="${anInstance.constraints.category.inList}" value="${anInstance?.category}"

Grails Scaffolding - define possible values for this property of a domain class

一个人想着一个人 提交于 2019-12-05 07:49:41
I am new to Grails. I have a Person domain class as : class Person { String firstName String lastName String gender Date dateOfBirth } And wondering if I can define possible values for a property - say gender as {M, F, U} so that these three values will be listed in combo box when using dynamic scaffolding for Person controller. Here I just wanted to know if there is such feature in Grails framework? If such feature exists , then how can I use it? From the documentation http://grails.org/doc/latest/guide/scaffolding.html , you should be able to use an inList constraint: class Person { String

How to set uniqueness at DB level for a one-to-many association?

不想你离开。 提交于 2019-12-04 13:52:08
问题 My problem is simple but I could not find any GORM syntax for this. Consider the following class: class Article { String text static hasMany = [tags: String] static constraints= { tags(unique: true) //NOT WORKING } } I want to have one unique tag name per article defined in my constraints but I cannot make it with the above syntax. Clearly I need in DB schema something like: create table article_tags (article_id bigint, tags_string varchar(255), unique (article_id , tags_string)) How can I do