LittleJack has asked for the wisdom of the Perl Monks concerning the following question:
I'm probably not doing this the right way, I should be generating the new model automatically through some kind of script?
But it's not a 100% standard Catalyst setup, and I'm kind of in a hurry.
I have a set of Models already in the site which look like this:
use utf8; package Model::DB::Result::Thing; use base 'DBIx::Class::Core'; use strict; use warnings; __PACKAGE__->table("things"); # etc. etc. some fields are defined here __PACKAGE__->add_columns( "id", { data_type => "integer", is_auto_increment => 1, is_nullable => 0, }, "name", { data_type => "text", is_nullable => 1 },
So I need to add another Model along the lines of:
use utf8; package Model::DB::Result::OtherThing; use base 'DBIx::Class::Core'; use strict; use warnings; __PACKAGE__->table("otherthings"); # etc. etc. some fields are defined here __PACKAGE__->add_columns( "id", { data_type => "integer", is_auto_increment => 1, is_nullable => 0, }, "othername", { data_type => "text", is_nullable => 1 },
And I'm doing it by the naïve method of putting a new OtherThing.pm into the same directory, restarting, and trying to call on it from a Controller.
This doesn't work and I get [error] Caught exception in Console::Controller::OtherThing->create "Can't call method "create" on an undefined value at /var/www/Payment/Console/lib/Console/Controller/OtherThing.pm line xx."
Where the undefined thing is $c->model('OtherThing')
So is there some other flag or listing or module which controls which of my Models get loaded? There's a load_namespaces step in booting up Catalyst, I know that much.
Happy to do it the correct way via the correct script if I can, but I need to get it working either way.
I can see the Model being loaded when Catalyst starts up, by the way:
[debug] Loaded components: .--------------------------------------------------------------------- +------------------------------------+----------. | Class + | Type | +--------------------------------------------------------------------- +------------------------------------+----------+ | Console::Controller::OtherThing + | instance | | [snip] + | | | Console::Model::DB::Thing + | class | | Console::Model::DB::OtherThing + | class |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: I need help adding a new model to a legacy Catalyst setup
by NERDVANA (Priest) on Mar 20, 2022 at 04:14 UTC | |
by LittleJack (Beadle) on Mar 20, 2022 at 20:11 UTC | |
|
Re: I need help adding a new model to a legacy Catalyst setup
by Your Mother (Archbishop) on Mar 18, 2022 at 01:36 UTC | |
|
Re: I need help adding a new model to a legacy Catalyst setup
by Bod (Parson) on Mar 18, 2022 at 01:11 UTC |