Strip trailing _id from single-column belongs_to relationships
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / RelBuilder.pm
index ab2e20d..e969bae 100644 (file)
@@ -170,10 +170,11 @@ sub generate_code {
         my $remote_relname;
 
         # for single-column case, set the remote relname to the column
-        # name, to make filter accessors work
+        # name, to make filter accessors work, but strip trailing _id
         if(scalar keys %cond == 1) {
-            my ($col) = keys %cond;
-            $remote_relname = $self->_inflect_singular($cond{$col});
+            my ($col) = values %cond;
+            $col =~ s/_id$//;
+            $remote_relname = $self->_inflect_singular($col);
         }
         else {
             $remote_relname = $self->_inflect_singular(lc $remote_table);