title: Save hasMany association
body: <p>I have an Entity <strong>Card</strong> and another <strong>ExercisesGroup</strong>.</p>
  
  <pre><code>Card HAS MANY ExercisesGroup
  
  // Fields
  Card = name
  ExercisesGroup = name, card_id
  </code></pre>
  
  <p>App\Model\Table\CardsTable</p>
  
  <pre><code>    $this-&gt;hasMany('ExercisesGroups', [
          'foreignKey' =&gt; 'card_id'
      ]);
      public function validationDefault(Validator $validator)
      {
          $validator
              -&gt;add('id', 'valid', ['rule' =&gt; 'numeric'])
              -&gt;allowEmpty('id', 'create')
              -&gt;requirePresence('name', 'create')
              -&gt;notEmpty('name')
  
          return $validator;
      }
  </code></pre>
  
  <p>App\Model\Table\ExercisesGroupTable</p>
  
  <pre><code>    $this-&gt;belongsTo('Cards', [
          'foreignKey' =&gt; 'card_id'
      ]);
      public function validationDefault(Validator $validator)
      {
          $validator
              -&gt;add('id', 'valid', ['rule' =&gt; 'numeric'])
              -&gt;allowEmpty('id', 'create')
              -&gt;requirePresence('name', 'create')
              -&gt;notEmpty('name')
              -&gt;add('card_id', 'valid', ['rule' =&gt; 'numeric'])
              -&gt;requirePresence('card_id', 'create')
              -&gt;notEmpty('card_id');
  
          return $validator;
      }
      public function buildRules(RulesChecker $rules)
      {
          $rules-&gt;add($rules-&gt;existsIn(['card_id'], 'Cards'));
          return $rules;
      }
  </code></pre>
  
  <p>I need save ExercisesGroup when I save Card, like this:</p>
  
  <p>App\Controller\Controller\CardsController</p>
  
  <pre><code>$data = [
    'name' =&gt; 'foo',
    'exercises_groups' =&gt;
      [
        ['name' =&gt; 'exercise bar']
      ]
  ];
  $card = $this-&gt;Cards-&gt;newEntity();
  $card = $this-&gt;Cards-&gt;patchEntity($card, $data);
  $this-&gt;Cards-&gt;save($card);
  </code></pre>
  
  <p>The issue is, I'm getting this validation error:</p>
  
  <pre><code>[
      'exercises_groups' =&gt; [
          (int) 0 =&gt; [
              'card_id' =&gt; [
                  (int) 0 =&gt; 'This field is required'
              ]
          ]
      ]
  ]
  </code></pre>
  
  <p>I know card_id is empty but I can't set card_id because I dont saved card yet so I don't know what it will be, I read the documentation and i thought the framework handle this, what can I be doing wrong?</p>
  
  <p><strong>Clue</strong> Cakephp is recognizing the association because Is validation ExercisesGroup data. The question Is: Why they requesting foreign key instead filling automatically.</p>