apache / apache/grails-core

New Mapping for static compilation doesn't create constraints

Open
#14,524 2 comments 0 reactions 0 assignees View on GitHub
relates-to: gorm
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

Using the new mapping Gorm DSL with MappingBuilder,
the mapping on the database is correct,
but the mapping is not translated in any constraints.

### Steps to Reproduce

1. Create a basic domain

```
@CompileStatic
class Sample {

String optional
String shorttext

static mapping = orm {
property "optional", { nullable true }
property "shorttext", { maxSize 5 }
}
}
```

2. Create a basic unit test like

```
class SampleSpec extends Specification implements DomainUnitTest {

def setup() {
}

def cleanup() {
}

void "test optional"() {
given:
Sample sample = new Sample()
when:
sample.validate()
then:
!sample.hasErrors()
}

void "test maxSize"() {
given:
Sample sample = new Sample()
sample.optional = "value"
sample.shorttext = "123456"
when:
sample.validate()
then:
sample.hasErrors()
}
}
```

### Expected Behaviour
Both validation tests should pass

### Actual Behaviour
Both validation test fails

I expect that mapping definition will imply constraints.

Alternatively constraints definition could follow the MappingBuilder paradigm like
```
static constraints = orm {
property "optional", { nullable true }
property "shorttext", { maxSize 5 }
}
```
This is very useful in Ide, in particular now that Intellij lint for Grails is broken from more than a year.

### Environment Information

- **Operating System: MacOs 10.14.3
- **GORM Version: 6.1
- **Grails Version: 3.3.8
- **JDK Version: 1.8

Contributor guide

Open the contributing guide

Research direction

Start with the MappingBuilder DSL entry point and the DomainUnitTest validation path described in the report. Reproduce the issue with Sample and SampleSpec, then verify that nullable and maxSize mappings become validation constraints and both tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.