Grails
  1. Grails
  2. GRAILS-3826

Unique constraint not part of domainClass.constrainedProperties

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.1-beta2
    • Fix Version/s: None
    • Component/s: Persistence
    • Labels:
      None

      Description

      If you have a property which has a unique consraint defined, the unique constraint is not part of the domainClass.constrainedProperties.

      In most cases people won't be bothered, but if you are trying to get most out domain class meta data available then it's usefull.

      E.g. in the i18n-templates-plugin I'm generating labels for all domain classes, properties and constraints.
      Currently I'm not able to check if a property has a unique key constraint defined.

        Activity

        Hide
        Marcel Overdijk added a comment - - edited
        // print error messages for constraints
        cp = domainClass.constrainedProperties[p.name]
        cp?.appliedConstraints?.each { c ->
            switch (c.name) {
                        case ConstrainedProperty.BLANK_CONSTRAINT:
                            println "${domainClass.propertyName}.${p.name}.${c.name}.error=Property [${p.naturalName}] of class [${domainClass.shortName}] cannot be blank"
                            break
                        case ConstrainedProperty.CREDIT_CARD_CONSTRAINT:
                            println "${domainClass.propertyName}.${p.name}.${c.name}.error=Property [${p.naturalName}] of class [${domainClass.shortName}] with value [{2}] is not a valid credit card number"
                            break
        
                        //case ConstrainedProperty.UNIQUE_CONSTRAINT: // unique constraint reference not available
                        //    println "${domainClass.propertyName}.${p.name}.${c.name}.error=Property [${p.naturalName}] of class [${domainClass.shortName}] with value [{2}] must be unique"
                        //    break
            }
        }
        
        Show
        Marcel Overdijk added a comment - - edited // print error messages for constraints cp = domainClass.constrainedProperties[p.name] cp?.appliedConstraints?.each { c -> switch (c.name) { case ConstrainedProperty.BLANK_CONSTRAINT: println "${domainClass.propertyName}.${p.name}.${c.name}.error=Property [${p.naturalName}] of class [${domainClass.shortName}] cannot be blank" break case ConstrainedProperty.CREDIT_CARD_CONSTRAINT: println "${domainClass.propertyName}.${p.name}.${c.name}.error=Property [${p.naturalName}] of class [${domainClass.shortName}] with value [{2}] is not a valid credit card number" break // case ConstrainedProperty.UNIQUE_CONSTRAINT: // unique constraint reference not available // println "${domainClass.propertyName}.${p.name}.${c.name}.error=Property [${p.naturalName}] of class [${domainClass.shortName}] with value [{2}] must be unique" // break } }

          People

          • Assignee:
            Unassigned
            Reporter:
            Marcel Overdijk
          • Votes:
            4 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Last Reviewed:

              Development