【发布时间】:2011-01-09 18:12:38
【问题描述】:
我是 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”列来执行此操作。当类别没有父级(根级别)时,其 parentid 为 0。
我有一个 GSP 试图显示有关父母的数据(如果有)。
<g:if test="${category.parent}">
hello
</g:if>
我的印象是这将测试存在。 如果类别确实有父类别,它工作正常,但是一旦 parentid=0,它就会爆炸。
No row with the given identifier exists: [ProductCategory#0]
我尝试检查 ==0,但没有成功,我认为是因为 'parent' 应该是一个对象。
那么我怎样才能让它假设 parentid=0 与 parent=null 或 NO parent 相同?
谢谢
【问题讨论】:
-
你在哪里设置 parentid=0 ?
-
我没有设置。这是一个只读应用程序,当类别没有父级时,我现有的数据的 parentid=0。