Grails/GORM question regarding missing method

98 views
Skip to first unread message

Robert Stagner

unread,
Mar 11, 2015, 4:58:09 PM3/11/15
to grails-de...@googlegroups.com
All,

I'm new to Grails and have been experimenting with attempting to reverse engineer some tables from a legacy database (I've been using the db-reverse-engineer plugin).  When I attempt to run the following code against the domain classes that have been generated

def license = new License()
def myArtist = new Artist()
myArtist.with {
name = "Tester Jester"
typeId = 2
setupById = "stagr005"
setupDate = new Date()
}
license.with {
project = "Test Oh Sweet Test"
projectTypeId = 2 // Trailer
fee = new BigDecimal("35000.00")
feeCurrencyId = 153 // US Dollars
licenseeId = 661 // Paramount
contractDate = new Date() - 10
licenseStatusId = '1' // License is in-progress
licenseTermId = 'P' // perpetual
setupById = 'stagr005'
setupDate = new Date()
// licenseProductId -- what is this for????
artist = myArtist
territory = new Territory()
}
myArtist.addToLicenses(license)
myArtist.save(failOnError: true)

I get the following error

Caught: groovy.lang.MissingMethodException: No signature of method: Artist.addToLicenses() is applicable for argument types: (License) values: [License : (unsaved)]

Please see the following Gist for the complete Groovy script and a list of the domain classes: https://gist.github.com/restagner/0e8644ad1955d839b19f

I was under the impression that I could use the addTo* style methods to add certain domain objects.  I'm sure that  I'm overlooking something obvious here, but I just can't quite figure it out.  I have reviewed the Grails documentation, but could not pick up on where I'm going wrong


Bobby Warner

unread,
Mar 11, 2015, 5:15:22 PM3/11/15
to grails-de...@googlegroups.com
Please ask usage questions on StackOverflow.

To answer your question though, you need to correctly define the relationships in your domain classes (hasMany / belongsTo) in order to use addTo methods.  Hope that helps!


Thanks,
Bobby

Robert Stagner

unread,
Mar 11, 2015, 5:31:51 PM3/11/15
to grails-de...@googlegroups.com
Ok, thanks.
Reply all
Reply to author
Forward
0 new messages