I have a table that I need to have a relation back to itself to support a concept where one record "requires" another in the same table. For example purposes the main table is tbl_myRecord and the join table is tbl_myRecordJoin.
CREATE TABLE tbl_myRecord (
id INT(10) UNSIGNED NOT NULL PRIMARY KEY,
name VARCHAR(50),
INDEX (id)
);
CREATE TABLE tbl_myRecordJoin (
myRecordId INT(10) UNSIGNED NOT NULL,
myRecordJoinId INT(10),
INDEX (myRecordId, myRecordJoinId)
);
I have then appropriately modified the controller to save values into tbl_myRecordJoin. The problem is that the saved records do not show up as "selected" when viewing the saved record.
How do I make the saved values show as "selected"?
As a followup to this what I have discovered is that my original code will submit all the values that were selected but will not show the ones that have been selected.
it will show the previously saved values however when I save new values it will only submit one of them in the $_POST variable. $selectedItems is an array that contains the ids of the saved records.
Why are CActiveForm::dropDownList and CHtml::dropDownList implemented differently?
The “myRecord[fieldName][]” can be any string you want, but the “myRecord” should match the name of the model so that “fieldName[]” will become an array within the $_POST[‘myRecord’] array to make processing the selected records easier in the controller.