Hi, I hope someone can help me with a problem I am having with the user and roles structure as defined in the catalyst tutorial. I am working on a new project using Catalyst, DBIx::Class and HTML::FormFu I am fairly new to these 3 modules.
I have used the tables and I am now trying to use a FormFu form to allow me to create a new user and assign roles to them. I am getting the following error:
Caught exception in Indium::Controller::Admin::User->create "The primary key and the foreign key may not be the same column in class Indium::Schema::Result::UserRole at .....
I have tried adding a new id column to user_role and making it the primary key however this breaks the inbuilt $c->check_any_user_role('myrolename'); this does not error but returns false instead of true as expected and what was occurring before adding the id field as primary. Removing the primary also does not work.
FormFu roles select:
- type: Select
label: Role
multiple: 1
name: user_roles
model_config:
resultset: Role
label_column: role
id_column: id
The user creation itself is working if I remove the roles from the form.
This is the user role_model
__PACKAGE__->table("user_role");
__PACKAGE__->add_columns(
"user_id",
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
"role_id",
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
);
__PACKAGE__->set_primary_key("user_id", "role_id");
__PACKAGE__->belongs_to(
"role",
"Indium::Schema::Result::Role",
{ id => "role_id" },
{ is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE"
+ },
);
__PACKAGE__->belongs_to(
"user",
"Indium::Schema::Result::User",
{ id => "user_id" },
{ is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE"
+ },
);
__PACKAGE__->meta->make_immutable;
1;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.