2

私はプロファイルとライセンスと呼ばれるmygrailsプロジェクトに2つのクラスを持っています。クラスで重要なものの概要は次のとおりです

class Profile {

    Set<Licence> licenceKeys

    static hasMany = [licenceKeys:Licence]

   static constraints = {
        licenceKeys nullable:true
    }
    static mapping = {
        licenceKeys cascade: 'all-delete-orphan'
    }
}

class Licence {

    Profile profile
    String licenceKey

    static belongsTo = [profile:Profile]

    static constraints = {
        profile nullable:false
        licenceKey blank:true, nullable:true, unique:true
    }   
}

コントローラーの 1 つで次のコードを実行すると、

    if (!profile.licenceKeys.clear()) {
        log.error ("Error occured removing licence keys from the database");
        userProfile.errors.each { err -> println err; }
    }  else {
        log.info("Successfully remove licence keys from the database");
    }

コンソールに次のエラー メッセージが表示され、licencekeys がデータベースに残ります

2 つの質問があります。表示されたエラー メッセージのデバッグ出力を改善することはできますか?

ありがとう

4

1 に答える 1

0

このclear()メソッドは、 の後に保存するデータベースから削除する作業を実際には行いませんclear()。試す...

profile.licenceKeys.clear();
if (!profile.save(flash:true)) {
    log.error ("Error occured removing licence keys from the database");
    userProfile.errors.each { err -> println err; }
}  else {
    log.info("Successfully remove licence keys from the database");
}

2 番目の質問では、保存に失敗したドメイン オブジェクトからエラーを取得する必要があります。

 if (!profile.save(flash:true)) {
    log.error ("Error occured removing licence keys from the database");
    profile.errors.each { err -> println err; }
}
于 2012-11-15T13:31:50.740 に答える