[Dbix-class] Can't find source for XXX question
ejm
mansky at mindspring.com
Thu Nov 29 22:57:50 GMT 2018
Hi All,
Another newbie question about the "Can't find source for XXX" error message.
I've been able to establish a connection to my MySQL DB by specifying a storage type for my Schema,
but I keep getting the "Can't find source for XXX" error message when I try searching the table XXX.
In my Schema object I have :
__PACKAGE__->load_namespaces();
and the usual "use base qw(DBIx::Class::Schema);
so that methods are correctly inherited from DBIx::Class::Schema.
Then I have a new constructor in my Schema object which blesses my object in the namespace I need it in:
sub new {
my ($proto, $db) = @_;
my $class = ref($proto) || $proto;
my $self = bless {}, $class;
$self->storage_type('::DBI::mysql');
return $self->connect($dsn, $dbuser, $dbpw, { AutoCommit => 1});
}
where $db is the MySQL DB I need to access and $dbuser, $dbpw are local variables containing the usual User and PW.
and $dsn = "dbi:mysql:database=$db";
I've checked the object returned by the constructor and it has the expected entries:
class_mappings => { 'X::Y::Z::Result::Table1' => 'Table1',
'X::Y::Z::Result::Table2' => 'Table2',
...
},
source_registrations => {
'Table1' => bless( { 'result_class' => 'X::Y::Z::Result::Table1',
'resultset_class' => 'X::Y::Z::ResultSet::Table1',
'name' => 'Table1',
'source_name' => 'Table1',
...
}, 'DBIx::Class::ResultSource::Table'},
...
},
storage => { '_connect_info' => [ 'dbi:mysql:database=VSO',
'dbuser',
'dbpw',
{
'AutoCommit' => 1
},
'_conn_pid' => 10779,
...
}
I see an entry in source_registrations for each of the tables in the DB VSO, all with their correct columns.
However, I noted that the objects are all blessed into the generic DBIx::Class::ResultSource::Table class and not
the X::Y::Z::ResultSource::Table1 class as I would have expected.
Is that why I am getting the "Can't find source ..." error message ?
I have a package for each table in X::Y::Z::Result namespace and additionally a package for the table I am testing
in both X::Y::Z::ResultSource::Table1 and X::Y::Z::ResultSet::Table1
I noted that the resultset_class key above was indeed set to my namespace-specific package for my test table.
Any tips or ideas would be greatly appreciated.
Thanks,
--Ed
More information about the DBIx-Class
mailing list