Parts hasMany Attributes and Attributes belongsTo attribute_types. This allows the user to create arbitrary attributes (like "weight" for instance) that all parts inherit and whose value can be set on a per- part basis. These associations seem to work well.
But a problem arises because if the part doesn't have any attribute values already set (or only some are set), then those fields do not show up in the edit form because they are not part of the loop. But the fields should show up no matter if they are blank or not. So, for the view, I simply passed a list of attribute types to the view, then match up ID's with the part data. Not very efficient but it works. foreach($AttTypes as $a) { echo "<tr><td width=200>" . $a['AttributeType']['name'] . ":</ td><td>"; foreach($part['Attribute'] as $pa) { if($a['AttributeType']['id'] == $pa['attribute_type_id']) { echo $pa['attribute_value']; } } echo "</td></tr>"; } So moving onto the add/edit, I ran into the problem as well. Again, the attribute input fields are not put out because the model doesn't actually contain the attribute fields. So again, I pass a list of attribute_types and walk through them. foreach($AttTypes as $k=>$at) { echo $form->input('Attribute.' . $k . '.attribute_value', array('label'=>$at['AttributeType']['name'])); echo $form->input('Attribute.' . $k . '.id',array('type'=>'hidden')); echo $form->input('Attribute.' . $k . '.attribute_type_id',array('type'=>'hidden')); } The problem is it's not setting the attribute_type_id properly. The data that gets submitted during an edit is: [Attribute] => Array ( [0] => Array ( // this value was already in the DB so the type_id gets properly passed [attribute_value] => Yes [id] => 4 [attribute_type_id] => 2 ) [1] => Array ( // this value was set for the first time during the edit [attribute_value] => foo [id] => [attribute_type_id] => // missing type id ) ) What ends up happening is cake puts everything where it's supposed to when you save it, only the attribute_type_id is missing simply because it wasn't passed. So basically I have to set the input value for attribute_type_id if it's not set already but I have no idea how to do that. Additionally, as I'm typing this, I realized maybe I'm going about this wrong? Maybe, In the controller, I should be "building" the model before passing the data to the view? i.e. I check to make sure all attribute structures are in the model data passed to the view. For the add view, I'd manually add all the attributes, and for the edit view, I'd add any attributes that don't have values. (?) -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php