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;

In reply to Catalyst with DBIx::Class User Roles Error by Boydle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.