[Dbix-class] add_column oddness - what am I missing ? (a newbie
question)]
Richard Robinson
catalyst at beulah.qualmograph.org.uk
Mon Jun 18 13:06:25 GMT 2007
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 ?)
--
Richard Robinson
"The whole plan hinged upon the natural curiosity of potatoes" - S. Lem
More information about the Dbix-class
mailing list