views:

24

answers:

1

Hi,

I've got an issue with Grails where I have a test app with:

class Artist {
static constraints = {
 name()
}

 static hasMany = [albums:Album]
 String name
}

class Album {
 static constraints = {
  name()
}

 static hasMany = [ tracks : Track ]
 static belongsTo = [artist: Artist]

 String name
}

class Track {

 static constraints = {
  name()
  lyrics(nullable: true)
 }

 Lyrics lyrics
 static belongsTo = [album: Album]

 String name
}

The following query (and a more advanced, nested association query) works in the Grails Console but fails with a groovy.lang.MissingMethodException when running the app with 'run-app':

def albumCriteria = tunehub.Album.createCriteria()
def albumResults = albumCriteria.list {
 like("name", receivedAlbum)
 artist { like("name", receivedArtist) } // Fails here
maxResults(1)
}

Stacktrace:

groovy.lang.MissingMethodException: No signature of method: java.lang.String.call() is applicable for argument types: (tunehub.LyricsService$_getLyrics_closure1_closure2) values: [tunehub.LyricsService$_getLyrics_closure1_closure2@604106]
Possible solutions: wait(), any(), wait(long), each(groovy.lang.Closure), any(groovy.lang.Closure), trim()
at tunehub.LyricsService$_getLyrics_closure1.doCall(LyricsService.groovy:61)
at tunehub.LyricsService$_getLyrics_closure1.doCall(LyricsService.groovy)
(...truncated...)

Any pointers?

A: 

what exactly does this constraint mean? Seems suspect to me...

static constraints = {
    name()
}

is what you want?

static constraints = {
    name(nullable:false, blank: false)
}
Aaron Saunders
Every property has a default constraint. When you specify one in the constraints block with no parameters, it takes on the the defaults but scaffolding uses it for order of fields in the view. It has nothing to do with the OPs problem.
Gregg