views:

58

answers:

1

Hello,
Usecase: Player may have award or may not have. If player never had any award then Award will be null, ( 1. Is there any other way to do this.. without null.. I don't feel its good idea)
I am generating scaffold for following domain structure.

class Player {
    String name
    Award recentAward
    static constraints = {
        recentAward(nullable:true)
    }
}

class Award {
    String awardName
    int reputation
    Player bloodBag
    static belongsTo=Player
    static constraints = {
    }
}

When I create Player.. I do not provide Award.. when I create Award.. Selecting Player is compulsory.. from drop-down. Now, After creating few Players, we can create Award with appropriate Player selection. But when opened in list or show view. Player is blank, I mean it is null, not set when Award was created.

In save() of AwardController statement println(awardInstance.player); prints proper value. and I also did awardInstance.player.save() after println statement, but in vain.

+1  A: 

Check out the documentation on the hasOne relationship that was added in grails 1.2 (just released).

It allows you to define the Player/Award relationship where the Award would then have the foreign key to the player (if it exists).

Ted Naleid