Grails、Groovy、GSPは初めてです。
ドメインクラス「ProductCategory」があります。
class ProductCategory {
static constraints = {
}
static mapping = {
table 'product_category';
version false;
cache usage: 'read-only';
columns {
parent column: 'parentid';
procedure column: 'procid';
}
}
static hasMany = [children:ProductCategory];
ProductProcedure procedure;
Integer lineorder;
String name;
ProductCategory parent;
String templatelink;
char offline;
String toString() {
return id + " (" + name + ")";
}
}
各カテゴリは親を持つことができます。私は既存のデータベースを使用していますが、テーブルにはそれを行うための列'parentid'があります。カテゴリに親(ルートレベル)がない場合、その親IDは0です。
親に関するデータがある場合はそれを表示しようとしているGSPがあります。
<g:if test="${category.parent}">
hello
</g:if>
私はこれが存在をテストするだろうという印象を受けました。カテゴリに親がある場合は正常に機能しますが、parentid=0になるとすぐに爆発します。
No row with the given identifier exists: [ProductCategory#0]
== 0をチェックしようとしましたが、機能しませんでした。「親」がオブジェクトであると想定されているためだと思います。
では、parentid=0がparent=nullと同じである、または親がないと仮定するようにするにはどうすればよいですか?
ありがとう