[Jifty-commit] r3553 - in apps/CASPlus/trunk: lib/CASPlus/Model

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Tue Jun 26 09:14:46 EDT 2007


Author: sterling
Date: Tue Jun 26 09:14:45 2007
New Revision: 3553

Modified:
   apps/CASPlus/trunk/   (props changed)
   apps/CASPlus/trunk/lib/CASPlus/Model/ProfileRelationship.pm

Log:
 r7645 at dynpc145:  andrew | 2007-06-14 23:45:15 -0500
 Modifying ProfileRelationship to be more careful about one-to-one relationships and use the new record_class method.


Modified: apps/CASPlus/trunk/lib/CASPlus/Model/ProfileRelationship.pm
==============================================================================
--- apps/CASPlus/trunk/lib/CASPlus/Model/ProfileRelationship.pm	(original)
+++ apps/CASPlus/trunk/lib/CASPlus/Model/ProfileRelationship.pm	Tue Jun 26 09:14:45 2007
@@ -246,7 +246,7 @@
         $link_table_parent->create(
             model_class     => $link_table,
             name            => 'parent',
-            refers_to_class => $args->{relation_parent}->model_class->name,
+            refers_to_class => $args->{relation_parent}->record_class,
         );
 
         # Create the link table child column
@@ -254,7 +254,7 @@
         $link_table_child->create(
             model_class     => $link_table,
             name            => 'child',
-            refers_to_class => $args->{relation_child}->model_class->name,
+            refers_to_class => $args->{relation_child}->record_class,
         );
 
         # Create the relationship to the children via the link table
@@ -294,17 +294,17 @@
             $child_column->create(
                 model_class     => $args->{relation_child}->model_class,
                 name            => $parent_name,
-                refers_to_class => $args->{relation_parent}->model_class->name . 'Collection',
+                refers_to_class => $args->{relation_parent}->record_class . 'Collection',
                 refers_to_by    => $child_name,
             );
         }
 
-        # One-to-one or One-to-Many with only a single parent
+        # One-to-one or One-to-many with only a single parent
         else {
             $child_column->create(
                 model_class     => $args->{relation_child}->model_class,
                 name            => $parent_name,
-                refers_to_class => $args->{relation_parent}->model_class->name,
+                refers_to_class => $args->{relation_parent}->record_class,
             );
         }
 
@@ -316,17 +316,38 @@
             $parent_column->create(
                 model_class     => $args->{relation_parent}->model_class,
                 name            => $child_name,
-                refers_to_class => $args->{relation_child}->model_class->name . 'Collection',
+                refers_to_class => $args->{relation_child}->record_class . 'Collection',
                 refers_to_by    => $parent_name,
             );
         }
 
-        # One-to-one or one-to-many relationship with one child
+        # One-to-many relationship with one child
+        elsif ($args->{many_parents}) {
+            $parent_column->create(
+                model_class     => $args->{relation_parent}->model_class,
+                name            => $child_name,
+                refers_to_class => $args->{relation_child}->record_class,
+            );
+        }
+
+        # Special case: one-to-one
         else {
+            # With one-to-many, the relationships are constructed so that one
+            # side is handled with a Jifty::DBI::Record and the other with a
+            # Jifty::DBI::Collection.
+            #
+            # In the case of one-to-one, we need to take care not to use two
+            # Jifty::DBI::Records without adding a 'by' clause to one of them.
+            # Otherwise, a column would be created in both classes, which would
+            # be incorrect. Therefore, In the special case of one-to-one, we
+            # always store the actual link in the child and then make the
+            # parent refer to the relationship there.
+
             $parent_column->create(
                 model_class     => $args->{relation_parent}->model_class,
                 name            => $child_name,
-                refers_to_class => $args->{relation_child}->model_class->name,
+                refers_to_class => $args->{relation_child}->record_class,
+                refers_to_by    => $parent_name,
             );
         }
 


More information about the Jifty-commit mailing list