What I want to do: I have a users, user_roles and roles table. I want to have a set of select boxes for a user for each possible role, and then update the user_roles table to say, for example, that user 1 has roles 1,2,3 if roles 1,2, and 3 were selected on the form. I can get the page to list off the roles, but nothing gets saved to the database upon a submit. I've tried looking at the tests, but I can't quite figure out which one would be applicable.
Here goes: Schema: MyApp::Schema::DB::Result::Users: __PACKAGE__->might_have( 'user_contact_info' => 'MyApp::Schema::DB::Result::Address', 'user_id' ); __PACKAGE__->has_many( 'user_roles' => 'MyApp::Schema::DB::Result::UserRoles', 'user_id' ); __PACKGE__->many_to_many( 'roles' => 'user_roles', 'role_id' ); MyApp::Schema::DB::Result::Roles: __PACKAGE__->has_many( 'user_roles' => 'MyApp::Schema::DB::Result::UserRoles', 'role_id' ); __PACKGE__->many_to_many( 'users' => 'user_roles', 'user_id' ); MyApp::Schema::DB::Result::UserRoles: __PACKAGE__->belongs_to( 'user' => 'MyApp::Schema::DB::Result::Users', 'user_id' ); __PACKAGE__->belongs_to( 'role' => 'MyApp::Schema::DB::Result::Roles', 'role_id' ); Short description: I have a portion of a form that deals with users. They have contact information (let's say just an address for now) and then I want a list of all possible roles they could hold, with a checkbox for each to grant/de-grant that role to that particular user. My formconfig looks like the following: --- elements: - type: Block nested_name: user_contact_info elements: - type: Text label: Street name: street [... etc etc for address stuff ...] - type: Checkboxgroup name: users model_conifg: resultset: Roles If I try to pull the -type: Checkboxgroup out of the nested portion, I get a completely different error, about how UserRoles doesn't have relationship role_id (which really really confuses me, because none of my relationships are named role_id) Here is my problem: If I set resultset: Roles in the config, I get the following error: Caught exception in MyApp::Controller::User->user_edit "need a schema or context at C:/Perl/site/lib/HTML/FormFu/Element/_Group.pm line 74" If, however, I change that to model: Roles, then I get a nice list of all the roles with a checkbox. But then the data doesn't get saved to the database. I want all the checked roles to get put into the UserRoles table so that, for example if user 1 has roles 1,2,3, then UserRoles will have rows [1,1],[1,2],[1,3] (user_id,role_id). I do see that when I submit the form (using the model: Roles, since using resultset: Roles keeps erroring out), I'm getting something like this upon submit in the body: user_contact_info.users: 1,2,3 But, as I've mentioned, no saves. As near as I can tell, these are the relevant parts of the doc, but it's not working when I try either: http://search.cpan.org/~cfranks/HTML-FormFu-Model-DBIC-0.03007/lib/HTML/FormFu/Model/DBIC.pm#many_to_many_selection http://search.cpan.org/~cfranks/HTML-FormFu-Model-DBIC-0.03007/lib/HTML/FormFu/Model/DBIC.pm#options_from_model Do I need to set both model: and resultset? I've set my schema in the config. Here it is: <Controller::HTML::FormFu> <model_stash> schema DB </model_stash> </Controller::HTML::FormFu> I'm also still confused as to wether it should be schema: DB or schema DB. Neither one seems to make much of a difference either way.
_______________________________________________ HTML-FormFu mailing list HTML-FormFu@lists.scsys.co.uk http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu