2010-11-23 98 views
0

现在假设你有一个数据库的结构是这样的:的ColdFusion 9 ORM - 如何定义关系

对象

{ 
    id, 
    name 
} 

ObjectRelation

{ 
    id, 
    parentID, -- points to id in the object table 
    childID -- points to id in the object table 
} 

什么我” d喜欢在我的模型中有以下内容:

{ 
    property name 
    property children 
    property parent 
} 

如何在这种情况下定义父项属性?请记住,根元素显然没有父对象。

+1

我觉得你只是想一个对多为儿童和家长 – 2010-11-23 15:40:05

回答

0

这是你在找什么?

component persistent="true" { 
property name="id" ormtype="integer" type="numeric" column="id" fieldtype="id" generator="identity"; 
property name="name"; 
property name="children" 
    fieldtype="one-to-many" 
    cfc="Object" 
    linktable="ObjectRelation" 
    fkcolumn="parentID" 
    singularname="child" 
    lazy=true 
    inversejoincolumn="childID"; 
property name="parent" 
    fieldtype="many-to-one" 
    cfc="Object" 
    linktable="ObjectRelation" 
    fkcolumn="childID" 
    lazy=true 
    inversejoincolumn="parentID"; 
}