开发者

coldfusion 9 orm - how to define relationship

开发者 https://www.devze.com 2023-01-26 18:26 出处:网络
now pretend you have a db structure like this: table Object { id, 开发者_如何学编程 name } table ObjectRelation

now pretend you have a db structure like this:

table Object

{
    id,
   开发者_如何学编程 name
}

table ObjectRelation

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

what i'd like to have in my model is the following:

{
    property name
    property children
    property parent
}

how would you guys define the parent property in this case? keep in mind that the root element(s) obviously don't have a parent object.


Is this what you were looking for?

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";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消