|
Hi all, I have been trying to get linked tables to work, but I need
some help here… First a little background information. I have a table called
”tblNode” with a primary key ”NodeID” (there are other
columns as well, but I leave them out for simplicity). In addition I have a linking table called ”tblRelation”
with two columns ”MainNodeID” and ”RelatedNodeID”.
These two columns are both primary keys, and foreign keys (referencing the
NodeID of tblNode). So, If I have three records in the tblNode table (NodeID=1,NodeID=2
and NodeID=3), I can relate these nodes by creating records in the tblRelation
table. If tblRelation have a record with MainNodeID=1 and RelatedNodeID=3, it
would mean that Node 3 is related to Node 1… yeah, I think you get it by
now. Pretty simple example, but I have some problems getting the
Reactor XML configuration right.. From reading the documentation (and looking at examples), I
have worked out the following <objects> part of the configuration: <object name="tblNode"> <hasMany
name="Main"> <link
name="tblRelation" /> </hasMany> <hasMany
name="Related"> <link
name="tblRelation" /> </hasMany> </object> <object name="tblRelation"> <hasOne
name="tblNode" alias="Main"> <relate
from="MainNodeID" to="NodeID" /> </hasOne> <hasOne
name="tblNode" alias="Related"> <relate
from="RelatedNodeID" to="NodeID" /> </hasOne> </object> Leaving it like this, and using the following CF code raises
the error ”Invalid Object Type, The Type argument must be one of: table,
view” : <cfscript> reacta=createObject("component","reactor.reactorFactory").init(expandPath("/environment/itoolspro/reactor/reactor.xml")); record=reacta.createRecord("tblNode"); record.setNodeID(75); record.load(); mainIt=record.getMainIterator(); </cfscript> <cfdump var="#mainIt#"> The idea of this code is to load one Node record, and then
be able to iterate through all related Nodes (that is all Nodes where this Node
is the ”Main” node). My guess is that I can’t use the alias from the hasOne
in the tblRelation configuration, when defining the hasMany in tblNode…
but how would I then distinguish the two ”links” as they both point
to the same table.. All the examples I have seen have used a linking table to
link two different tables, not two times the same table.. Is it possible to do what I intend to do with Reactor as it
is today (and how would I do it), or do I have to stick with customized query
for this one to work... If there is something unclear in my explanation, please let
me know and I will try to describe it more thoroughly. Regards, Tormod Boga Inbusiness AS |

