开发者

Grails Scaffolding is not storing reference for given domain structure

开发者 https://www.devze.com 2022-12-15 07:35 出处:网络
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)

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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消