私はダンサーとダンスの間にHABTMの関係があります。ダンスを編集するためのedit.ctpで、CakePHPが期待していた複数選択ボックスの代わりにドロップダウンボックスを表示していることを除いて、物事は期待どおりに機能しているようです。私にとっておかしなのは、ダンサーを編集するために、複数選択ボックスがedit.ctpと逆に機能していることです。なぜそれが一方の方法で機能するのか、もう一方の方法では機能しないのか理解できません。
これが、ダンスとダンサーの関係を定義する私のダンスモデルです。
    public $belongsTo = array(
        'User' => array(
            'className' => 'User',
            'foreignKey' => 'user_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );
/**
 * hasAndBelongsToMany associations
 *
 * @var array
 */
    public $hasAndBelongsToMany = array(
        'Dancer' => array(
            'className' => 'Dancer',
            'joinTable' => 'dancers_dances',
            'foreignKey' => 'dance_id',
            'associationForeignKey' => 'dancer_id',
            'unique' => 'keepExisting',
        )
    );
これは私のダンスコントローラーです:
public function edit($id = null) {
    if (!$this->Dance->exists($id)) {
        throw new NotFoundException(__('Invalid dance'));
    }
    if ($this->request->is('post') || $this->request->is('put')) {
        if ($this->Dance->save($this->request->data)) {
            $this->Session->setFlash(__('The dance has been saved'));
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The dance could not be saved. Please, try again.'));
        }
    } else {
        $options = array('conditions' => array('Dance.' . $this->Dance->primaryKey => $id));
        $this->request->data = $this->Dance->find('first', $options);
    }
    $users = $this->Dance->User->find('list');
    $dancers = $this->Dance->Dancer->find('list');
    $this->set(compact('users', 'dancers'));
}
これはダンスビューの私のedit.ctpです
<div class="dances form">
<?php echo $this->Form->create('Dance'); ?>
    <fieldset>
        <legend><?php echo __('Edit Dance'); ?></legend>
    <?php
        echo $this->Form->input('id');
        echo $this->Form->input('dance_name');
        echo $this->Form->input('users_id');
        echo $this->Form->input('Dancers');
    ?>
    </fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
<div class="actions">
    <h3><?php echo __('Actions'); ?></h3>
    <ul>
        <li><?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $this->Form->value('Dance.id')), null, __('Are you sure you want to delete # %s?', $this->Form->value('Dance.id'))); ?></li>
        <li><?php echo $this->Html->link(__('List Dances'), array('action' => 'index')); ?></li>
        <li><?php echo $this->Html->link(__('List Dancers'), array('controller' => 'dancers', 'action' => 'index')); ?> </li>
        <li><?php echo $this->Html->link(__('New Dancers'), array('controller' => 'dancers', 'action' => 'add')); ?> </li>
    </ul>
</div>
関連するテーブルは次のようになると思います:dancers、dancers_dances、dances
dancers_dancesテーブルには、id、dancer_id、dance_idの列があります。
さらに情報が役立つかどうか教えてください。
前もって感謝します。