(I submitted this before but realized that I may not have explained it 
simply enough and I didn't word wrap for text email readers... my bad.)

Attached is a patch that allows for a table to have a foreign key to 
itself.  An example of such a relationship would be a folder table where 
each record could have a reference to a parent folder.

Currently there is a check in the Object.vm template that short circuits 
the generation of the accessors to objects related by foreign key if the 
name of the local table is the same as the foreign table.  Does anyone 
have any background on why this short circuit was put in place?  We're 
hoping it was just because the issue of handling recursive foreign key 
relationships was deferred.

Scott Finnerty

Index: jakarta-turbine-torque/src/templates/om/Object.vm
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-torque/src/templates/om/Object.vm,v
retrieving revision 1.31
diff -u -r1.31 Object.vm
--- jakarta-turbine-torque/src/templates/om/Object.vm   28 May 2002 01:00:16 -0000     
 1.31
+++ jakarta-turbine-torque/src/templates/om/Object.vm   30 May 2002 21:39:23 -0000
@@ -331,12 +331,11 @@
  ##
  #foreach ($fk in $table.Referrers)
   #set ( $tblFK = $fk.Table )
-  #if ( !($tblFK.Name.equals($table.Name)) )
    #set ( $className = $tblFK.JavaName )
    #set ( $relatedByCol = "" )
    #foreach ($columnName in $fk.LocalColumns)
     #set ( $column = $tblFK.getColumn($columnName) )
-    #if ($column.isMultipleFK())
+    #if ($column.isMultipleFK() || $tblFK.Name.equals($table.Name) )
         #set ($relatedByCol= "$relatedByCol$column.JavaName")
     #end
    #end
@@ -563,7 +562,7 @@
 
         return $collName;
     }
-  #end #end #end #end
+  #end #end #end
 
 ## ===========================================================
 #*
Index: jakarta-turbine-torque/src/templates/om/Object.vm
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-torque/src/templates/om/Object.vm,v
retrieving revision 1.31
diff -u -r1.31 Object.vm
--- jakarta-turbine-torque/src/templates/om/Object.vm   28 May 2002 01:00:16 -0000     
 1.31
+++ jakarta-turbine-torque/src/templates/om/Object.vm   30 May 2002 21:39:23 -0000
@@ -331,12 +331,11 @@
  ##
  #foreach ($fk in $table.Referrers)
   #set ( $tblFK = $fk.Table )
-  #if ( !($tblFK.Name.equals($table.Name)) )
    #set ( $className = $tblFK.JavaName )
    #set ( $relatedByCol = "" )
    #foreach ($columnName in $fk.LocalColumns)
     #set ( $column = $tblFK.getColumn($columnName) )
-    #if ($column.isMultipleFK())
+    #if ($column.isMultipleFK() || $tblFK.Name.equals($table.Name) )
         #set ($relatedByCol= "$relatedByCol$column.JavaName")
     #end
    #end
@@ -563,7 +562,7 @@
 
         return $collName;
     }
-  #end #end #end #end
+  #end #end #end
 
 ## ===========================================================
 #*
--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to