[Jifty-commit] r3675 - in jifty/branches/virtual-models: .

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Wed Jul 11 21:48:17 EDT 2007


Author: sterling
Date: Wed Jul 11 21:48:16 2007
New Revision: 3675

Modified:
   jifty/branches/virtual-models/   (props changed)
   jifty/branches/virtual-models/lib/Jifty/Model/ModelClassColumn.pm

Log:
 r8034 at dynpc145:  andrew | 2007-07-11 20:47:44 -0500
 Added a before_create handler to database-backed columns so that refers_to columns automatically get virtual or the storage_type set correctly.


Modified: jifty/branches/virtual-models/lib/Jifty/Model/ModelClassColumn.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/Model/ModelClassColumn.pm	(original)
+++ jifty/branches/virtual-models/lib/Jifty/Model/ModelClassColumn.pm	Wed Jul 11 21:48:16 2007
@@ -154,6 +154,35 @@
         default is 0;
 };
 
+=head2 before_create
+
+Before creating the column, make sure that columns get setup correctly.
+
+=cut
+
+sub before_create {
+    my $self = shift;
+    my $args = shift;
+
+    # Referals need special treatment
+    if (defined $args->{refers_to_class}) {
+
+        # Refer to a collection and your column is virtual
+        if ($args->{refers_to_class}->isa('Jifty::DBI::Collection')) {
+            $args->{virtual} = 1;
+        }
+
+        # Refer to a record and your column needs to be an int
+        elsif ($args->{refers_to_class}->isa('Jifty::DBI::Record')) {
+            $args->{storage_type} = 'int';
+        }
+
+        # XXX Can a column refer to something else? -- sterling
+    }
+
+    return 1;
+}
+
 =head2 after_create
 
 Upon creation of a metacolumn object, update the actual table to add an actual column.


More information about the Jifty-commit mailing list