[Uml-devel] [Bug 77377] New: SQL code generator generates "circular reference" foreign keys

Maciej J.Woloszyk mat at esi.com.pl
Mon Mar 15 01:12:03 UTC 2004


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
      
http://bugs.kde.org/show_bug.cgi?id=77377      
           Summary: SQL code generator generates "circular reference"
                    foreign keys
           Product: umbrello
           Version: 1.2
          Platform: unspecified
        OS/Version: Linux
            Status: UNCONFIRMED
          Severity: normal
          Priority: NOR
         Component: general
        AssignedTo: umbrello-devel.kde.org
        ReportedBy: mat esi com pl


Version:           1.2 (using KDE 3.2.0, Gentoo)
Compiler:          gcc version 3.3.2 20031218 (Gentoo Linux 3.3.2-r5, propolice-3.3-7)
OS:          Linux (i686) release 2.4.22-gentoo-r7

When you use Umbrello to design SQL scheme using agregations to simulate foreign keys constraints the code generators creates foreign key constarint in both tables instead of the "source" (role B - as I assume looking at the arrowhead of the aggregation connection - which is a bit misleading) table. Below is the simple patch - it makes code generator to check the objects of the aggregations and only create constraint in one table. In the other table generator also places the constraint, but only as an SQL comment. I'm not sure how well will it work, but at least it works for me.

M.

----------------- umbrello-sqlwriter.patch ---------------------------
--- kdesdk-3.2.0-orig/umbrello/umbrello/codegenerators/sqlwriter.cpp    2003-09-21 10:41:52.000000000 +0200
+++ kdesdk-3.2.0/umbrello/umbrello/codegenerators/sqlwriter.cpp 2004-03-12 12:15:23.000000000 +0100
 @ -89,8 +89,14  @
        UMLAssociationList aggregations = c->getAggregations();
        if( forceSections() || !aggregations.isEmpty() ) {
                for(UMLAssociation* a = aggregations.first(); a; a = aggregations.next()) {
-                       sql << ",\n\tCONSTRAINT " << a->getName() << " FOREIGN KEY (" << a->getMultiB() <<
-                              ") REFERENCES " <<   a->getObjectA()->getName() << "(" << a->getMultiA() << ")";
+                       if( a->getObjectA()->getID()==c->getID() ) {
+                               sql << "\n-- CONSTRAINT " << a->getName() << " FOREIGN KEY (" << a->getMultiB() <<
+                                       ") REFERENCES " <<   a->getObjectA()->getName() << "(" << a->getMultiA() << ")";
+                       } else {
+                               sql << ",\n\tCONSTRAINT " << a->getName() << " FOREIGN KEY (" << a->getMultiB() <<
+                                       ") REFERENCES " <<   a->getObjectA()->getName() << "(" << a->getMultiA() << ")";
+
+                       }
                }
        }




More information about the umbrello-devel mailing list