Skip to content

Commit

Permalink
Choose the validate method that doesn't have any arguments (non-varar…
Browse files Browse the repository at this point in the history
…gs method)

- respondsTo returns all methods matching, including varargs methods
  • Loading branch information
lhotari committed Oct 3, 2013
1 parent 0f74a69 commit 6e18f71
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ class GormInstanceApi<D> extends AbstractGormApi<D> {
protected D doSave(D instance, Map params, Session session, boolean isInsert = false) {
boolean hasErrors = false
boolean validate = params?.containsKey("validate") ? params.validate : true
List<MetaMethod> validateMethods = instance.respondsTo('validate')
if (validateMethods && validate) {
MetaMethod validateMethod = instance.respondsTo('validate', InvokerHelper.EMPTY_ARGS).find { MetaMethod mm -> mm.parameterTypes.length == 0 && !mm.vargsMethod}
if (validateMethod && validate) {
session.datastore.setSkipValidation(instance, false)
hasErrors = !validateMethods.get(0).invoke(instance, InvokerHelper.EMPTY_ARGS)
hasErrors = !validateMethod.invoke(instance, InvokerHelper.EMPTY_ARGS)
}
else {
session.datastore.setSkipValidation(instance, true)
Expand Down

0 comments on commit 6e18f71

Please sign in to comment.