artemave has asked for the wisdom of the Perl Monks concerning the following question:

Greetings,

I'm trying to DBIx::Class in a mod_perl 2 environment (Win32).
I've made a base class:
package dir_browse::model::DB::Main; use warnings; use strict; use base qw/DBIx::Class::Schema::Loader/; __PACKAGE__->loader_options(relationships => 1, debug => 1); sub get_schema { return __PACKAGE__->connection('dbi:mysql:database=dir_browse', 'r +oot', 'sa', {AutoCommit => 1}); } 1;
Then I'm getting schema from the model class:
package dir_browse::model::dir_browse; use strict; use warnings; ... use dir_browse::model::DB::Main; sub new { bless { schema => &dir_browse::model::DB::Main::get_schema(), ... } } ... sub get_contents { my $self = shift; ... $self->{dir} = $self->{schema}->resultset('t_dir')->search({dr_pat +h => $dir}) or $self->{schema}->create('t_dir')->({dr_path => $dir}); ... }
Running this produces the following error:
DBIx::Class::Schema::resultset(): Can't find source for t_dir
prepended by the following warning:
No tables found in database, nothing to load at c:/Perl/site/lib/DBIx/ +Class/Sche ma/Loader/Base.pm line 443.
whilst there are tables:
mysql> use dir_browse; Database changed mysql> show tables; +----------------------+ | Tables_in_dir_browse | +----------------------+ | t_dir | | t_dir_type | | t_session | | t_user | +----------------------+
What am I doing wrong?

Thanx,
Artem.

Replies are listed 'Best First'.
Re: Problem with DBIx::Class
by stonecolddevin (Parson) on May 06, 2007 at 05:38 UTC

    You need a class for each table, with all the table properties/columns defined in it. Unless you haven't posted this code, I can't see it anywhere in what you've shown us. Start with that and let us know if it helps. ALso, you might want to try using more hardcoded paths instead of all that config file/OO overhead while you're still getting the hang of DBIC. That way, you can sort out your errors a little more efficiently.

    Hope this helps!

    meh.
      Correct me if I'm wrong, but using DBIx::Class::Schema::Loader, I don't need to define table classes (check out this example in its manual).

      Thanx,
      Artem.