gorm


Domain class auto validation in grails


I am fetching list of results from database but the list doesn't validates the constraints until i call "validate()" method for each objects.
def temp = ConfigInfo.where { projectId == project }.findAll()
//at this stage domain class is not validated
temp.each {
println "validate" + it.validate()
println "has error" + it.hasErrors()
}
//in the above code block validate() is called, I don't want to do this.
// is it possible to configure it happen automatically and i get the validated objects.
I don't want to invoke validate method.
is there any way or configuration in grails such that domain class get validated automatically.
Please help me in this.
Grails domain class objects get validated before save.
Use the following in your domain model to set the validation rules:
static constraints = {
// whatever you want to validate
}
Whenever you save an object it will be validated by the constraints you set. When the object is persistent in the database it has always been validated.
All you need to do is that just define all your validation in constraints closure.
e.g.
static constraints = {
id maxLength: 5
//etc...
}
at the time of saving object you just need to check object is validate or not!, it will return true/false.
look this: click here

Related Links

“grails.mongodb.default.mapping” equivalent in application.yml in Grails 3.2
TenantId is null when saving an entity in a Discriminator based multi tenant application in Grails 3.2 with GORM 6
Grails 3 (unsaved) instance issue while fetching from database (GORM)
Can't use get() in domain using Grails3
GORM findAll + cannot pass dynamic List as named parameter
How to display database records in grails
Configure Grails 3.0.9 for Oracle 12c with identity PK?
Adding condition to findAll and findAllBy methods
Neo4j and Mongodb as datasource in Grails
GORM (varchar .save(), non DATE): ORA-01861: literal does not match format string
GORM addTo methods not found in Spock test
spring-boot property exception while externalizing datasource properties and using actuator
Mapping hasMany relation and saving the related data
Method on class [] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails Correctly
What happens when two app servers in cluster start LiquiBase update (via Grails)?
use of mappedBy in Many to Many relationship in Grails

Categories

HOME
openlayers
webpack
debugging
single-sign-on
adb
yarn
paw-app
fsm
nano-server
rascal
n-gram
commonmark
messages
serverless-framework
saxon
pythonanywhere
ml
abi
claims-based-identity
wijmo
angular2-aot
sparse-matrix
bootstrap-material-design
publish
log4js-node
newline
delicious-api
fabric8
bcd
twilio-api
uisplitview
airconsole
fog
column-family
windows-dev-center
openoffice.org
android-nestedscrollview
lto
mixture-model
webdriver-manager
elasticsearch-plugin
mesos-chronos
broadcastreceiver
nxlog
isbn
outlook-api
btrace
apple-news
wso2carbon
taffy
youcompleteme
slickedit
tactic
media-player
ifs
synchronous
xcb
gridpane
azure-virtual-network
pagedlist
hill-climbing
bluemix-app-scan
system.management
phpcas
hsv
rgeo
php-ci
sniffer
unity5.2.3
csquery
rake-task
asp.net-dynamic-data
android-nested-fragment
xcode-6.2
app42
geos
dataservice
ora-00911
free-variable
itmstransporter
newtonscript
assembly-loading
nsdatecomponents
boost-filesystem
tomcat-valve
locationlistener
gdlib
modelstate
fixed-width
user-friendly
temporal-database

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App