Richard Robinson wrote:
> On Mon, Jun 18, 2007 at 09:32:22AM +0100, Jess Robinson 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 and give a complete list to the
>>> __PACKAGE__->add_columns startup call, I have to deal with them on the fly.
>>> On startup, look at the state of the sql table to see what columns it does
>>> contain, and on new input create new columns in it as necessary ...
>> I suspect it's to do with how you're doing that ->add_columns calling at 
>> runtime, it would be quite helpful if you posted code to go with your 
>> problems ;)
> 
> Yes, I probably should have, sorry. It was just getting wordier than I liked
> already ...
> 
> 
> in the table module :-
> package EditTunesDB::TuneTable;
> use base qw/DBIx::Class/;
> #stuff
> __PACKAGE__->table('abctable');
> __PACKAGE__->add_columns(qw/id owner_id etc/);  # not including 'T'
> 
> 
> and at runtime (error-checking etc removed for clarity) :-
> 
> my $result = $c->model('EditTunesDB::TuneTable');
> my $src = $result->result_source;
> my $dbh = $src->storage->dbh;
> my $q = $dbh->prepare("SELECT * FROM abctable;");
> $q->execute();
> 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.
> }
> 
> # and test
> my $row = $result->find({id=>1});
> $c->log->debug("get_column(id) " . $row->get_column('id') );
> $c->log->debug("get_column(T) "  . $row->get_column('T') );
> $c->log->debug("->id " . $row->id );
> $c->log->debug("->T "  . $row->T );
> 
> and the 1st 3 print okay, the 4th throws an exception "Can't locate object
> method "T" via package "EditTunes::Model::EditTunesDB::TuneTable".
> 
> 
> This is being called from code behind a Catalyst controller action; which is
> another indication of a horrible lack of understanding - it only needs to be
> called once, but I haven't been able to find a suitable entrypoint. (I'm
> reading all the FMs I can find as fast as I can digest them, okay ?)
> 

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.

-=Chris

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to