[Dbix-class] add_column oddness - what am I missing ? (a newbie question)]

Richard Robinson catalyst at beulah.qualmograph.org.uk
Mon Jun 18 16:55:57 GMT 2007


On Mon, Jun 18, 2007 at 11:03:53AM -0400, Christopher H. Laco wrote:
> >> On Sat, 16 Jun 2007, Richard Robinson wrote:
> >>
> >>> Since I don't know in advance what keys it might meet, I can't create all
> >>> the possible columns beforehand ...
> > 
> > for (my $n = 0; $n < $q->{NUM_OF_FIELDS}; $n++)
> > { my $name = $q->{NAME}->[$n];
> >   next if ( $src->has_column($name) );
> >   $src->add_column( $name );
> >   # column 'T' exists and is seen here.
> > }
> 
> Sorry. I'm late to the party. I add/remove columns at runtime in Handel.
> To make that work, I had to add columns to the source AND to the class:
> 
> $schema->source('Foo')->add_column
> $schema->class('Foo')->add_column
> 
> If would work for me no other way, which isn't surprising because the
> original intent of add_column was not to do it at runtime.
> 
> In your loop above, try adding to the class as well just to see if it
> makes a difference.

Aha. Yes, it does the trick, the ->name form now returns the value instead
of blowing up. Thanks.

It's still a horribly-designed kludge, but at least it behaves as I'd
thought it would. This is progress.


-- 
Richard Robinson
"The whole plan hinged upon the natural curiosity of potatoes" - S. Lem




More information about the Dbix-class mailing list