Hopefully this will be an easy one to answer. I created a class in Grails called player which has this information:
class Player {
String steamId
String name
String portrait
static hasMany = {playerStatistics:PlayerStatistics}
static hasOne = {playerForumProfile:PlayerForumProfile}
}
For clarification, a Player object can have one PlayerForumProfile object, but the player object is always created BEFORE the PlayerForumProfile object. My issue is with accessing the playerForumProfile object associated with the "hasOne" property within the controller of the PlayerForumProfile class. I had assumed that doing this:
def playerForumProfileInstance = new PlayerForumProfile()
def playerInstance = Player.get(params.id)
playerForumProfileInstance = playerInstance.playerForumProfile
would result in pulling the PlayerForumProfile object associated with the playerInstance object into the playerForumProfileInstance variable, however when I try this, Grails throws an error telling me there is no such property as playerForumProfile. Is it possible to access the hasOne properties' object in such a manner or do I need to do something else?
Edit: I also tried modifying the Player class so it included a variable called playerForumProfile and editing PlayerForumProfile so it had a belongsTo declaration, but this kept resulting in a null pointer exception when running my app.
Edit: A little more info, I created a new grails app from scratch and created the relationship the way it appears in the Grails documentation and it ran with no problem so I'm thinking it may be easier just to start a new app and copy the files over.