[Dancer-users] SimpleCRUD and multiple tables

gizmo mathboy gizmomathboy at gmail.com
Mon Jun 4 05:43:50 CEST 2012


On 05/28/2012 05:07 AM, David Precious wrote:
> On Fri, 25 May 2012 11:02:00 -0400
> <gizmomathboy at gmail.com> wrote:
> 
>> Is there a way to access multiple tables using SimpleCRUD without
>> using foreign keys?
>>
>> I have a relatively small database with a 3 tables or so but I don't
>> have foreign keys between the tables.
> 
> Not currently; I've been working on such abilities, but it's awaiting
> further tuits.  The progress so far is in the feature/foreignkeys
> branch of the repo:
> 
> https://github.com/bigpresh/Dancer-Plugin-SimpleCRUD
> 
> Despite the name, it will work even if they are not designated as
> foreign keys in the database.
> 
> It's fairly basic so far.
> 
> I hope to have time to work on this module further soon, but I've been
> busy with various stuff lately which has taken time away from personal
> coding projects.

I created a rather ugly hack to do what I need.

--- SimpleCRUD.pm	2012-06-03 22:12:36.257043296 -0400
+++ SimpleCRUD-orig-with-gizmo.pm	2012-06-03 22:16:24.490175040 -0400
@@ -260,6 +260,18 @@

 sub simple_crud {
     my (%args) = @_;
+    if ( exists $args{prefix} ) {
+      _create_simple_crud_routes(%args);
+    }
+    else {
+      for my $args ( @_ ) {
+          _create_simple_crud_routes(%$args);
+      }
+    }
+}
+
+sub _create_simple_crud_routes {
+    my (%args) = @_;

     # Get a database connection to verify that the table name is OK, etc.
     my $dbh = database($args{db_connection_name});

The call goes from:

simple_crud (
    prefix => '/table1',
    record_title => 'Table1',
    db_table => 'table1',
);

to

simple_crud (
  {
    prefix => '/table1',
    record_title => 'Table1',
    db_table => 'table1',
  },
  {
    prefix => '/table2',
    record_title => 'Table2',
    db_table => 'table2',
  },
);

Yeah, ugly.

Now to do a pull request and look at that branch...

gizmo


More information about the Dancer-users mailing list