[Jifty-commit] r6969 - jifty/trunk/lib/Jifty/Manual

Jifty commits jifty-commit at lists.jifty.org
Sun May 10 11:18:16 EDT 2009


Author: c9s
Date: Sun May 10 11:18:15 2009
New Revision: 6969

Modified:
   jifty/trunk/lib/Jifty/Manual/Cookbook.pod

Log:
new entry in Manual::Cookbook:  Render model refers_to field as a select widget with meaningful display name


Modified: jifty/trunk/lib/Jifty/Manual/Cookbook.pod
==============================================================================
--- jifty/trunk/lib/Jifty/Manual/Cookbook.pod	(original)
+++ jifty/trunk/lib/Jifty/Manual/Cookbook.pod	Sun May 10 11:18:15 2009
@@ -311,6 +311,38 @@
 
 Check details from Angus himself. ( http://www.twinhelix.com/ )
 
+=head2 Render model refers_to field as a select widget with meaningful display name
+
+Sometimes you need to render a column which is using C<refers_to> to other
+model. but you want not to display id of the entries , but meaningful display
+name instead.
+
+    use Jifty::DBI::Schema;
+    use MyApp::Record schema {
+            column colors => 
+                refers_to MyApp::Model::Color;
+    };
+
+you can implement a C<name> method in ModelColor:
+
+    package MyApp::Model::Color;
+    use Jifty::DBI::Schema;
+
+    use MyApp::Record schema {
+
+    column color_name =>
+        type is 'varchar';
+
+    };
+
+    sub name {
+        my $self = shift;
+        return $self->color_name;
+    }
+
+so that, when you render an field which refers to MyApp::Model::Color , it will render
+a select widget with the mapping color names for you.
+
 =head2 Create mutually dependent models
 
 Sometimes you need two tables that both depend upon each other. That is, you have model A that needs to have a column pointing to Model B and a column in Model B pointing back to model A. The solution is very straight forward, just make sure you setup the base class I<before> you load dependent model and this will just work. For example:


More information about the Jifty-commit mailing list