title: Adding multiple records to a relations table with symfony
body: <p>I have setup 3 tables in symfony:</p>
  
  <p>A flipbook table, A Skills table, and a relations table, to connect each skill id with each flipbook id. </p>
  
  <p>WHen I built the model, symfony constructed everything correctly, and by default gave a drop-down menu for the skills, which had all skills from the skills table as options. You can select an option and it creates the appropriate relationships. </p>
  
  <p>This is working (sort of). When you submit the form, it does not add the skill_id to the record. It just adds the auto-increment id to the skills relations table and neither the flipbook_id or skill_id. Aaaaaand, if you click more than one checkbox, you get this nice message:</p>
  
  <pre><code>invalid parameter number number of bound variables does not match number of tokens
  </code></pre>
  
  <p>Whaaaat does that mean? This has got to be a schema issue eh?</p>
  
  <p>How about some code? yes.please.</p>
  
  <p><strong>Schema:</strong></p>
  
  <pre><code>Flipbook:
    tableName: flipbook
    inheritance:
      extends: SvaGeneric
      type: concrete
    columns:
      title: { type: string(255) }
      career_associations: { type: clob }
      skills: { type: string(255) }
      skills_associations: { type: clob }
      program: { type: string(255) }
      program_associations: { type: clob }
      draft_id: { type: integer(10) }
  
  FlipbookSkills:
    tableName: flipbook_skills
    columns:
      title: { type: string(255) }
    relations:
      Flipbook:
        foreignAlias: flipbook_skills
        alias: skills
        local: title
        onDelete: SET NULL   
  
  FlipbookSkillRelations:
    tableName: flipbook_skill_relations
    actAs:
      SoftDelete: ~
    options:
    columns:
      flipbook_id: { type: integer(10), notnull: false }
      skill_id: { type: integer(10), notnull: false }
    relations:
      Flipbook:
        foreignAlias: flipbook_skills_flipbook
        alias: flipbook
        local: flipbook_id
        onDelete: CASCADE
      FlipbookSkills:
        foreignAlias: flipbook_skills_skills
        alias: flipbookskills
        local: skill_id
        onDelete: CASCADE
  </code></pre>
  
  <p><strong>FlipbookSkillsRelationsForm.class.php:</strong></p>
  
  <pre><code>$this-&gt;widgetSchema['flipbook_id'] = new sfWidgetFormInputText(array(), array('class' =&gt; 'text size-500'));
  
  $this-&gt;widgetSchema['skill_id'] = new sfWidgetFormSelectCheckbox(array('choices' =&gt; "**WHAT GOES HERE??**"), array('class' =&gt; 'text size-500'));
  
  
  $useFields = array(
    'flipbook_id',
    'skill_id',
  );
  
  $this-&gt;useFields($useFields);
  </code></pre>
  
  <p>Let me know if I should provide further code or explanation.</p>
  
  <p>Here is the FlipbookSkillsTable.class generated in the model:</p>
  
  <pre><code>&lt;?php
  
  /**
   * FlipbookSkillsTable
   * 
   * This class has been auto-generated by the Doctrine ORM Framework
   */
  class FlipbookSkillsTable extends Doctrine_Table
  {
      /**
       * Returns an instance of this class.
       *
       * @return object FlipbookSkillsTable
       */
      public static function getInstance()
      {
          return Doctrine_Core::getTable('FlipbookSkills');
      }
  
      public function retrieveForFilter()
      {
        $res = $this-&gt;createQuery('s')
          -&gt;select('s.id, s.name')
          -&gt;orderBy('s.name ASC')
          -&gt;execute(array(), Doctrine_Core::HYDRATE_NONE);
  
        // if you want an empty line
        $rets = array('' =&gt; '');
        foreach ($res as $ret)
        {
          $rets[$ret[0]] = $ret[1];
        }
  
        return $rets;
      }
  
      public function getAllFlipbookSkills() {
          $allSkills = Doctrine_Query::create()
              -&gt;from('FlipbookSkills')
              -&gt;orderBy('title ASC')
              -&gt;execute();
      return $allSkills;
      }
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I believe the issue is it is trying to bind the multiple values in the same record. It should make a new record for each skill chosen, like this:</p>
  
  <pre><code>id    flipbook_id    skill_id
  1          2            1
  2          2            2
  3          2            3
  </code></pre>
  
  <p>SO I still don't have the schema nailed down correctly, otherwise Doctrine would know how to handle the data correct? Should I explicitly put one to many relationship?</p>
  
  <p>Also, when submitted, it is only adding the flipbook_id value to the record. The skill_id record is 0</p>
  
  <p><strong>FLipbookRelationsForm:</strong></p>
  
  <pre><code>class FlipbookSkillRelationsForm extends BaseFlipbookSkillRelationsForm
  {
    public function configure()
    {
  
      $this-&gt;widgetSchema['skill_id'] = 
         new sfWidgetFormDoctrineChoice(array('model' =&gt; 
             $this-&gt;getRelatedModelName('flipbookskills'), 
              'expanded' =&gt; true, 'multiple' =&gt; true, 'add_empty' =&gt; false));
  
      $useFields = array(
              'flipbook_id',
              'skill_id',
          );
  
      $this-&gt;useFields($useFields);
    }
  }
  </code></pre>