简体   繁体   中英

coldfusion 9 orm - how to define relationship

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM