2009/4/14 Dennis Daupert <ddaup...@gmail.com>: > Finding my way around, I thought I'd ask for advice before getting myself in > too much trouble ;-) > > I have several sets of parent / child / join tables in which both the > "parent (has many and many-to-many)" and "child (belongs to)" tables are > managed separately, and only the join tables need to be updated; e.g. , > users, roles, user_roles; projects, directories, project_directories. I am > wondering how to configure forms so that inserts, updates, deletes go to the > join tables? Or is it best to "hand roll" parameter value capturing and > database interactions. > > In HTML::FormFu::Model::DBIC I see examples showing yaml configurations for > updating tables that are related to one another -- via foreign keys, but I'm > not sure how to apply the example logic to my situation. > > For example, I have a form that has two Selects: projects and directories. > The user will select one project, and could select multiple directories. > Both Projects and Directories tables are prepopulated, so only the > projects_directories join table needs to be modified. Let me paste some bits > from the three tables, snipped for brevity: > > =============================== > package hde::Schema::Result::Projects; > __PACKAGE__->table("projects"); > __PACKAGE__->add_columns( > "id", { data_type => "INTEGER", is_nullable => 0, size => undef }, > "rel_tag", { data_type => "TEXT", is_nullable => 0, size => undef }, > > __PACKAGE__->has_many(map_project_directory => > 'hde::Schema::Result::ProjectDirectories', 'directory_id'); > __PACKAGE__->many_to_many(directories => 'map_project_directory', > 'directory'); > > =============================== > package hde::Schema::Result::Directories; > __PACKAGE__->table("directories"); > __PACKAGE__->add_columns( > "id", { data_type => "INTEGER", is_nullable => 0, size => undef }, > "directory", { data_type => "TEXT", is_nullable => 0, size => undef }, > > __PACKAGE__->has_many(map_project_directory => > 'hde::Schema::Result::ProjectDirectories', 'directory_id'); > > =============================== > package hde::Schema::Result::ProjectDirectories; > __PACKAGE__->table("project_directories"); > __PACKAGE__->add_columns( > "project_id", { data_type => "INTEGER", is_nullable => 0, size => undef > }, > "directory_id", { data_type => "INTEGER", is_nullable => 0, size => > undef }, > __PACKAGE__->belongs_to(project => 'hde::Schema::Result::Projects', > 'project_id'); > __PACKAGE__->belongs_to(directory => 'hde::Schema::Result::Directories', > 'directory_id'); > > =============================== > > Is/are there configuration settings that allow FormFu to easily handle this > sort of situation?
Hi Dennis, If you checkout the test files from the HTML-FormFu-Model-DBIC distribution, I think these ones match the setups you want: t/update/many_to_many_select.t t/update/many_to_many_select.yml t/default_values/has_many_select.t t/default_values/has_many_select.yml To allow the user to select/deselect related rows, you should either use a Select field with multiple(1) set, or a Checkboxgroup field. Or to only allow a single related row to be selected, use a Radiogroup field. Carl _______________________________________________ HTML-FormFu mailing list HTML-FormFu@lists.scsys.co.uk http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu