Sunday 15 April 2012

groovy - Grails BootStrap: No signature of method: *.addTo* applicable -



groovy - Grails BootStrap: No signature of method: *.addTo* applicable -

i have 2 domain classes: user

class user { string username string password string email date datecreated date lastupdated // static belongsto = [profile: profile] static constraints = { username size: 3..20, unique: true, nullable: false, validator: { _username -> _username.tolowercase() == _username } password size: 6..100, nullable: false, validator: { _password, user -> _password != user.username } email email: true, blank: false // profile nullable: true } }

and profile:

class profile { string firstname string middlename string lastname byte[] photo date datecreated date lastupdated static belongsto = [user] static constraints = { firstname blank: false middlename nullable: true lastname blank: false photo nullable: true, maxsize: 2 * 1024**2 } }

a profile can belong 1 user , user can have (or belong to?) 1 profile. when seek create objects in bootstrap.groovy in current setup error saying addto() method not exist. don't know doing wrong. how creating them in bootstrap.groovy:

user arun = new user(username: 'arun', password: 'password', email: 'arun@email.com').save(failonerror: true) profile arunprofile = new profile(firstname: 'arun', lastname: 'allamsetty').addtouser(arun).save(failonerror: true)

can please point out mistake(s). sure it's silly.

a strict bi-directional one-one relationship required have requested for:

a profile can belong 1 user , user can have (or belong to?) 1 profile

three modifications required in domain classes:

//user.groovy static hasone = [profile: profile] static constraints = { profile unique: true } //profile.groovy user user

above bi-directianl one-one relationship. not need addto* anymore while creating each of them.

profile arunprofile = new profile(firstname: 'arun', lastname: 'allamsetty') user arun = new user(username: 'arun', password: 'password', email: 'arun@email.com', profile: arunprofile).save()

grails groovy grails-domain-class

No comments:

Post a Comment