diff Lib/IMPL/ORM/Schema/TransformToSQL.pm @ 44:32d2350fccf9

ORM *Minor fixes *Working tarnsform to sql *Fixes to the sql traits
author Sergey
date Mon, 11 Jan 2010 01:42:00 +0300
parents d660fb38b7cc
children 16ada169ca75
line wrap: on
line diff
--- a/Lib/IMPL/ORM/Schema/TransformToSQL.pm	Thu Jan 07 15:41:49 2010 +0300
+++ b/Lib/IMPL/ORM/Schema/TransformToSQL.pm	Mon Jan 11 01:42:00 2010 +0300
@@ -19,7 +19,8 @@
         Field => \&FieldTransform,
         HasOne => \&HasOneTransform,
         HasMany => \&HasManyTransform,
-        Subclass => \&SubclassTransform
+        Subclass => \&SubclassTransform,
+        ValueType => sub {}
     }
 );
 
@@ -39,7 +40,7 @@
     my %ctx = (Schema => $schema);
     
     # all tables
-    foreach my $entity ($node->ReferenceTypes) {
+    foreach my $entity ($node->selectNodes('Entity')) {
         $schema->AddTable($this->Transform($entity,\%ctx));
         push @constraints, $entity->selectNodes(sub {$_->isa('IMPL::ORM::Schema::Relation')});
     }
@@ -80,14 +81,23 @@
     my $tableForeign = $sqlSchema->Tables->{$relation->target};
     my $prefix = $relation->name;
     
-    my @fkColumns = map
+    my @fkColumns = @{$tableForeign->PrimaryKey->Columns};
+    
+    if (@fkColumns > 1) {
+        @fkColumns = map
         $table->InsertColumn({
             Name => $prefix . $_->Name,
             Type => $_->Type,
             CanBeNull => 1
-        }),
-        @{$tableForeign->PrimaryKey->Columns};
-        
+        }), @fkColumns;
+    } else {
+        @fkColumns = $table->InsertColumn({
+            Name => $prefix,
+            Type => $fkColumns[0]->Type,
+            CanBeNull => 1
+        });
+    }
+    
     $table->LinkTo($tableForeign,@fkColumns);    
 }
 
@@ -99,21 +109,29 @@
     my $sqlSchema = $ctx->{Schema};
     my $table = $sqlSchema->Tables->{$relation->parentNode->entityName};
     my $tableForeign = $sqlSchema->Tables->{$relation->target};
-    my $prefix = $table->Name . '_' . $relation->name;
+    my $prefix = $relation->name;
     
-    my @fkColumns = map
-        $tableForeign->InsertColumn({
+    my @fkColumns = @{$table->PrimaryKey->Columns};
+    
+    if (@fkColumns > 1 ) {
+        @fkColumns = map $tableForeign->InsertColumn({
             Name => $prefix . $_->Name,
             Type => $_->Type,
             CanBeNull => 1
-        }),
-        @{$table->PrimaryKey->Columns};
+        }), @fkColumns;
+    } else {
+        @fkColumns = $tableForeign->InsertColumn({
+            Name => $prefix,
+            Type => $fkColumns[0]->Type,
+            CanBeNull => 1
+        });
+    }
         
     $tableForeign->LinkTo($table,@fkColumns);    
 }
 
 sub SubclassTransform {
-    # actually this rlations has only ligical implementation
+    # actually this rlations has only logical implementation
 }
 
 sub MapType {