]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole/Model/CDBI.pm
Remove "name" magic, replace with "stringify_column" magic.
[maypole.git] / lib / Maypole / Model / CDBI.pm
index b2a79b494d8699d6fa677625891e4d9136c28cbe..e7330e48abeafe98fe9ae807f5313cc13ee2e930 100644 (file)
@@ -61,12 +61,20 @@ sub delete :Exported {
     $r->{template} = "list";
 }
 
+sub stringify_column {
+    my $class = shift;
+    return ($class->columns("Stringify"),
+                (grep { $_ ne "id" } $class->primary_columns),
+                (grep { $_ eq "name" } $class->columns)
+               )[0];
+}
+
 sub adopt {
     my ($self, $child) = @_;
     $child->autoupdate(1);
-    if (grep { $_ eq "name" } $child->columns) { # Common case
-        $child->columns( Stringify => qw/ name / );
-    } # Otherwise, work it out for yourself.
+    if (my $col = $child->stringify_column) {
+        $child->columns( Stringify => $col );
+    }
 }
 
 sub search :Exported {