Form dropDownList column mismatch

Hey all, simple question:

I have two tables.

"Table Fees" contains a list of fees and their information.

ID | Name  | Charge

1  | Fee A | 10

2  | Fee B | 20

3  | Fee C | 30

"Table Associated Fees" contains a list of fees, as they apply to a customer, with other information.

ID | Customer | Fee | Modded Charge

3  | 100      | 2   | 25 

In the second table, the 3rd defined fee is associated to customer #100, is based off of Fee B, and is modified to charge $25 instead of $20.

The problem is, in the drop down list model, it autoselects an option based on matching IDs. Fee C would be selected, not Fee B.

How would I change this?

My temporary fix for this matter is to manually set the default.

echo $form->dropDownList($model,"fees[{$feeID}][fee]", CHtml::listData($fees, 'id', 'name'), array("empty" => "Nothing", "options" => (isset($model->fees[$feeID]) ? array($model->fees[$feeID]->fee => array("selected" => true)) : array()) ));

I’m still wanting to hear the actual fix so that these hacks are not needed.

well that looks like your relations are wrong. They should match = assoc.fee, but they match = Try to fix that and you should be able to getrid of the hack.