[Maypole] Re: Lazy relationship filling using Postgres constraints

From: philippe poumaroux (poumaroux at ifrance.com)
Date: Wed Jan 26 2005 - 13:46:36 GMT


First of all, thanks for your help.

In order to help further readers, I will sum up this item and precize
some points:

In order to retreave automatically relationship from database foreign
keys,
Class::DBI::Loader version 0.10+ is needed.

Second, it's necessary to instantiate its own Loader as follow :

BeerDB->config->loader(Class::DBI::Loader->new(
                              dsn => "dbi:Pg:dbname=beerdb",
                              user => "my_login",
                              password => "",
                              namespace => "BeerDB",
                              options => { AutoCommit => 1 }, # usefull
for Postgres
                              relationships => 1));

Finally, calling setup i still needed :

BeerDB->setup("dbi:Pg:dbname=beerdb", "my_login", "", {AutoCommit =>
1});

And it works on my Linux Box (Apache 2, mod_perl and Postgres 7.3.1),
using
Maypole 2.07.

But wrinting all this line only for activate one option seems to me
painfull,
so I propose the following patch adding a new config accessor
"relationships"
to Maypole. We still use the classic 'setup' line, we just have now to
add
before the following :

BeerDB->config->{relationships} = 1;

What do you think about it ?

diff -ru Maypole-2.09/lib/Maypole/Config.pm
Maypole-2.09-1/lib/Maypole/Config.pm
--- Maypole-2.09/lib/Maypole/Config.pm 2005-01-24 21:40:03.000000000
+0100
+++ Maypole-2.09-1/lib/Maypole/Config.pm 2005-01-26
14:26:00.962644752 +0100
@@ -11,7 +11,7 @@
 __PACKAGE__->mk_accessors(
      qw( view view_options uri_base template_root template_extension
model
          loader display_tables ok_tables rows_per_page dsn user pass
opts
- application_name)
+ relationships application_name)
 );
 
 # Should only be modified by model.
@@ -107,6 +107,11 @@
 
 Password for database user.
 
+=head3 relationships
+
+Flag to activate automatic relationship generation from database side
+foreign key defintion.
+
 =head3 opts
 
 Other options to the DBI connect call.
diff -ru Maypole-2.09/lib/Maypole/Model/CDBI.pm
Maypole-2.09-1/lib/Maypole/Model/CDBI.pm
--- Maypole-2.09/lib/Maypole/Model/CDBI.pm 2005-01-17
21:04:16.000000000 +0100
+++ Maypole-2.09-1/lib/Maypole/Model/CDBI.pm 2005-01-26
14:22:58.320410592 +0100
@@ -236,6 +236,7 @@
             dsn => $dsn,
             user => $u,
             password => $p,
+ relationships => $config->{relationships},
             options => $opts,
         )
     );

 ___[ Pub ]____________________________________________________________
Envie de discuter gratuitement avec vos amis ?
Téléchargez Yahoo! Messenger http://yahoo.ifrance.com
_____________________________________________________________________

Envie de discuter gratuitement avec vos amis ?
Téléchargez Yahoo! Messenger http://yahoo.ifrance.com

_______________________________________________
maypole mailing list
maypole at lists.netthink.co.uk
http://lists.netthink.co.uk/listinfo/maypole



This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:57 GMT