Ticket #52 (reopened defect)
HABTM collection_select()
| Reported by: | openface | Owned by: | somebody |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Action View | Version: | |
| Severity: | normal | Keywords: | |
| Cc: |
Description
Looking at a HABTM between employees and departments...
<?=collection_select("employee", "departments", $departments, "id", "name", array(), array("multiple"=>true))?>
I would expect this to display a multi-select (which it does), and be able to treat a HABTM association.
A couple of issues:
Firstly, when you pass "multiple" param, the name of the select input should be appended with parenthesis to allow for array passing via request:
<select name="employee[departments]">
Should become:
<select name="employee[departments][]">
Secondly, the values are being ignored when using collection_select() like this. In my case, I have an employee which belongs to 2 departments. The above call to collection_select() should not only display the multiple-select (which it does), but it should have the associated department IDs selected. (which it does not)
Am I using this function in the wrong way, or is the functionality just not built yet to handle HABTM with form helpers. ?
Many thanks..
