From: Aaron Trevena Date: Mon, 9 Jan 2006 17:42:17 +0000 (+0000) Subject: fixes to plain CDBI model X-Git-Tag: 2.11~72 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=3886be13f39d6d3fc8d0b76d4716175df1bb8056;p=maypole.git fixes to plain CDBI model git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@446 48953598-375a-da11-a14b-00016c27c3ee --- diff --git a/Changes b/Changes index fb23434..2c36970 100644 --- a/Changes +++ b/Changes @@ -69,6 +69,7 @@ Bug fixes: Reduced risk of XSS in factory templates (bug 16659) model search/delete methods in model and subclassing the cdbi mode (bug 16661) fixed problems with stringify_self and untaint missing ignore columns (bug 15678) + fixed Maypole::Model::CDBI::Plain to JustWork(TM) with plain CDBI Classes (bug 16977) Documentation: Fix to documentation for CGI::Maypole (bug 7263) diff --git a/lib/Maypole.pm b/lib/Maypole.pm index c18f695..5d3e259 100644 --- a/lib/Maypole.pm +++ b/lib/Maypole.pm @@ -194,7 +194,7 @@ synopsis of L for an example driver =cut -__PACKAGE__->mk_classdata($_) for qw( config init_done view_object ); +__PACKAGE__->mk_classdata($_) for qw( config init_done view_object model_classes_loaded); __PACKAGE__->mk_accessors( qw( params query objects model_class template_args output path @@ -206,6 +206,8 @@ __PACKAGE__->config( Maypole::Config->new() ); __PACKAGE__->init_done(0); +__PACKAGE__->model_classes_loaded(0); + =head1 HOOKABLE METHODS As a framework, Maypole provides a number of B - methods that are @@ -313,7 +315,7 @@ sub setup_model # Load custom model code, if it exists - nb this must happen after the # unshift, to allow code attributes to work, but before adopt(), # in case adopt() calls overridden methods on $subclass - $class->load_model_subclass($subclass); + $class->load_model_subclass($subclass) unless ($class->model_classes_loaded()); $config->model->adopt($subclass) if $config->model->can("adopt"); } diff --git a/lib/Maypole/Model/CDBI/Plain.pm b/lib/Maypole/Model/CDBI/Plain.pm index 37abc67..b76cff3 100644 --- a/lib/Maypole/Model/CDBI/Plain.pm +++ b/lib/Maypole/Model/CDBI/Plain.pm @@ -5,9 +5,13 @@ use strict; Maypole::Config->mk_accessors(qw(table_to_class)); + + sub setup_database { my ( $self, $config, $namespace, $classes ) = @_; $config->{classes} = $classes; + foreach my $class (@$classes) { $namespace->load_model_subclass(); } + $namespace->model_classes_loaded(1); $config->{table_to_class} = { map { $_->table => $_ } @$classes }; $config->{tables} = [ keys %{ $config->{table_to_class} } ]; } @@ -17,6 +21,9 @@ sub class_of { return $r->config->{table_to_class}->{$table}; } + + + 1; =head1 NAME