title: Saving relations in yii2 forms - how to avoid duplication in attributes?
body: <p>I have Student model (id, name, school_id) and School model (id, name, ...)
  The relation schema is:  school has many students, student can only have one school.</p>
  
  <pre><code>&lt;?php
  class School extends \yii\db\ActiveRecord
  {
  /*.....*/
  public function getStudents()
  {
      return $this-&gt;hasMany(Student::className(), ['school_id' =&gt; 'id']);
  }
  /*.....*/
  }
  ?&gt;
  </code></pre>
  
  <p>Now I want to render checkboxes for each student on the School create form:</p>
  
  <pre><code>&lt;?= $form-&gt;field($model, 'students')-&gt;checkboxList(ArrayHelper::map($allStudents, 'id', 'name')) ?&gt;
  </code></pre>
  
  <p>($model is School instance. For simplicity let's assume that there are not a lot of students - so checkboxes control is enough)</p>
  
  <p>Now, if I want to add validation rule to allow max 5 students (using School::rules() method) - on form submit I get 
  "Trying to set read-only attribute students"</p>
  
  <p>Okay, that means that AR relations are readonly attributes in models.</p>
  
  <p>But how I can use Yii2 activeForm and validations using rules then, without creation of another bogus attribute (student_ids) which won't be saved to db and will be used solely for validation purposes?</p>
  
  <p>Is there a "right" way here? 
  Thanks!</p>