うまくいけば、これは答えやすいものになるでしょう。次の情報を持つ player という Grails のクラスを作成しました。
class Player {
String steamId
String name
String portrait
static hasMany = {playerStatistics:PlayerStatistics}
static hasOne = {playerForumProfile:PlayerForumProfile}
}
明確にするために、Player オブジェクトは 1 つの PlayerForumProfile オブジェクトを持つことができますが、プレーヤー オブジェクトは常に PlayerForumProfile オブジェクトの前に作成されます。私の問題は、PlayerForumProfile クラスのコントローラー内の「hasOne」プロパティに関連付けられている playerForumProfile オブジェクトにアクセスすることです。私はこれを行うと仮定しました:
def playerForumProfileInstance = new PlayerForumProfile()
def playerInstance = Player.get(params.id)
playerForumProfileInstance = playerInstance.playerForumProfile
これを実行すると、playerInstance オブジェクトに関連付けられた PlayerForumProfile オブジェクトが playerForumProfileInstance 変数に取り込まれますが、これを試みると、Grails はエラーをスローして、playerForumProfile のようなプロパティがないことを知らせます。そのような方法で hasOne プロパティのオブジェクトにアクセスすることは可能ですか、それとも何か他のことをする必要がありますか?
編集: Player クラスを変更して、playerForumProfile という変数を含め、PlayerForumProfileを編集して、belongsTo宣言を含めようとしましたが、アプリの実行時に null ポインター例外が発生し続けました。
編集:もう少し情報、私はゼロから新しいgrailsアプリを作成し、Grailsのドキュメントに表示される方法で関係を作成し、問題なく実行されたので、新しいアプリを開始してコピーする方が簡単かもしれないと考えています以上のファイル。