Copy link to clipboard
Copied
Hi,
a rather simple database scheme
Object {
id,
name
}
ObjectRelation {
parentID, -- points to id in the Object table
childID -- points to id in the Object table
}
how would i define an Object Model component with properties
component {
property "name"
property "children"
property "parent"
}
obviously root object(s) don't have any parent elements.
Copy link to clipboard
Copied
Quick question - have you read *any* of the documentation? What have you tried thus far?
Copy link to clipboard
Copied
i actually RTFM! so far i got the children relationship working like this
property name="children"
fieldtype="one-to-many"
cfc="Object"
linktable="ObjectRelation"
fkcolumn="parentID"
singularname="child"
lazy=true
inversejoincolumn="childID";
i had the "inverse" version of this for the parent relationship, it didn't work all to well though.
property name="parent"
fieldtype="many-to-one"
cfc="Object"
linktable="ObjectRelation"
fkcolumn="childID"
lazy=true
inversejoincolumn="parentID";
with that whenever i try to call object.getParent().getName() i get a
Error Messages: Value must be initialized before use.
Its possible that a method called on a Java object created by CreateObject returned null.
Copy link to clipboard
Copied
Glad to hear it ![]()
I haven't done any ORM in a while so I'm sure someone will correct me, but I don't believe you need the linktable attribute unless it's a many-to-many; in your case you should be able to add a property to the child object called parent, with a cfctype of whatever it is, and a fkcolumn attribute of the foreign key column.
That should be all you need. Try cutting your attributes down to the absolute bear minimum and try that, alas I don't have a working example to hand I'm afraid.
O.
Copy link to clipboard
Copied
the relation is built with the ObjectRelation table, so i think ORM needs to know the
name of the relation table in order to get the parent.
what's more, in the hibernate log file i see alot of select with outer join, didn't disassamble them yet though. however, i believe that is why i get more objects than there actually are.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more