[Catalyst] Catalyst::Model::CDBI and AutoCommit/autoupdate
Colin Meyer
cmeyer at helvella.org
Sun Jun 5 21:04:34 CEST 2005
Hi,
On Sat, May 21, 2005 at 10:20:41AM +0200, Frank Wiegand wrote:
> Sebastian Riedel schrieb:
>
> >This was inherited from Maypole, and it's what most people want...
Yuck. Trying and failing to turn off autoupdate in Maypole is one of the
reasons that prompted me to try Catalyst.
> >
> >You could do something like this
> >
> > use NEXT;
> >
> > sub new {
> > my $self = shift->NEXT::new(@_);
> > $_->autoupdate(0) for $self->loader->classes;
> > return $self;
> > }
>
> Ah, ok. This'll work for me.
>
> Thanks, Frank
I tried this approach, but found that autoupdate was still turned on
for my Catalyst::M::CDBI::* generated classes. I'm too busy playing
with my application to dig into the Catalyst framework right now to see
why this isn't working. Is it possible that this new() is being called
to early? Hmm, that doesn't make sense, or the call to
$_->autoupdate(0) should fail.
This is with Catalyst 5.20, Catalyst::Model::CDBI 0.08.
I propose the attached patch to Catalyst::Model::CDBI, which passes
all tests.
Thanks for everyone's work on this interesting system!
-Colin.
-------------- next part --------------
*** CDBI.pm_orig 2005-06-05 11:57:44.961398371 -0700
--- CDBI.pm 2005-06-05 11:56:16.339162817 -0700
***************
*** 28,33 ****
--- 28,34 ----
password => '',
user => 'postgres',
options => { AutoCommit => 1 },
+ cdbi_autoupdate => 0, # defaults to 1
relationships => 1
);
***************
*** 56,61 ****
--- 57,63 ----
$self = $self->NEXT::new($c);
$self->{namespace} ||= ref $self;
$self->{additional_base_classes} ||= ();
+ my $autoupdate = delete $self->{cdbi_autoupdate};
push @{ $self->{additional_base_classes} }, ref $self;
eval { $self->loader( Class::DBI::Loader->new(%$self) ) };
if ($@) { $c->log->debug(qq/Couldn't load tables "$@"/) if $c->debug }
***************
*** 65,71 ****
if $c->debug;
}
for my $class ( $self->loader->classes ) {
! $class->autoupdate(1);
$c->components->{$class} ||= bless {%$self}, $class;
no strict 'refs';
*{"$class\::new"} = sub { bless {%$self}, $class };
--- 67,73 ----
if $c->debug;
}
for my $class ( $self->loader->classes ) {
! $class->autoupdate(defined( $autoupdate ) ? $autoupdate : 1);
$c->components->{$class} ||= bless {%$self}, $class;
no strict 'refs';
*{"$class\::new"} = sub { bless {%$self}, $class };
More information about the Catalyst
mailing list