[Catalyst] Pulling My Hair Out with DBIx::Schema For Authentication and Authorization
hkclark at gmail.com
hkclark at gmail.com
Tue Mar 21 22:06:05 CET 2006
On 3/21/06, Matt S Trout <dbix-class at trout.me.uk> wrote:
> hkclark at gmail.com wrote:
> > __PACKAGE__->table('user_roles');
> > (...)
> > CREATE TABLE user_role (
>
> *cough*
>
ARGH! Yes, you are correct. I have been testing this multiple times,
and I obviously grabbed the wrong version to send out to the list
(just my luck). :-(
I have updated my 3 result source classes to fix that error (along
with other things that were wrong in the previous versions). Updated
version are shown below.
Unfortunately, I still get the same error (with the same strange
SELECT showing up in the debug):
SELECT me.user_id, me.role_id FROM user_role me WHERE ( username = ? )
It's like it's not picking up the relationship to the user table...
it's got 'username' in the WHERE clause but no join to the 'user'
table.
If I haven't totally blown my credibility, :-\ suggestions/help would
be greatly appreciated.
Regards,
H
==============
package MyApp::Db::Schema::Role;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/PK::Auto::SQLite Core/);
__PACKAGE__->table('role');
__PACKAGE__->add_columns(qw/id name/);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->has_many(map_user_role => 'MyApp::Db::Schema::UserRole' => 'role');
1;
==============
package MyApp::Db::Schema::User;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/PK::Auto::SQLite Core/);
__PACKAGE__->table('user');
__PACKAGE__->add_columns(qw/id username password/);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->has_many(map_user_role => 'MyApp::Db::Schema::UserRole' => 'user');
1;
==============
package MyApp::Db::Schema::UserRole;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/PK::Auto::SQLite Core/);
__PACKAGE__->table('user_role');
__PACKAGE__->add_columns(qw/user role/);
__PACKAGE__->set_primary_key(qw/user role/);
1;
==============
package MyApp::Db::Schema;
use base qw/DBIx::Class::Schema/;
__PACKAGE__->load_classes(
{
'MyApp::Db::Schema' => [ qw/User UserRole Role/]
}
);
1;
==============
Also, here is the Class section of the server startup:
.---------------------------------------------------------+----------.
| Class | Type |
+---------------------------------------------------------+----------+
| MyApp::Controller::Login | instance |
| MyApp::Controller::Logout | instance |
| MyApp::Controller::Root | instance |
| MyApp::Model::DBIC | instance |
| MyApp::Model::DBIC::Role | class |
| MyApp::Model::DBIC::User | class |
| MyApp::Model::DBIC::UserRole | class |
| MyApp::View::TT | instance |
'---------------------------------------------------------+----------'
More information about the Catalyst
mailing list