title: Yii2 saving model with relationship property
body: <p>iam trying to save model from form, that have relationship defined via junction table, but since the property is relationship object it is read-only and it fails on validation.</p>
  
  <p>Model relationship:</p>
  
  <pre><code>public $payer
  /**
   * @return \yii\db\ActiveQuery
   */
  public function getPayerRelationship()
  {
      return $this-&gt;hasMany(PartyRelationship::className(), ['contract_id' =&gt; 'id'])-&gt;where(['relationship' =&gt; 'P']);
  }
  
  public function getPayers(){
      return $this-&gt;hasMany(ContractingParty::className(), ['id' =&gt; 'contracting_party_id'])
          -&gt;via('payerRelationship');
  }
  public function getContractors() {  // could be a static func as well
      $model = ContractingParty::find()-&gt;asArray()-&gt;all();
      return ArrayHelper::map($model, 'id', 'subject_name');
  }
  </code></pre>
  
  <p>Form view: </p>
  
  <pre><code>&lt;?= $form-&gt;field($model, 'payers')-&gt;widget(Select2::classname(), [
      'data' =&gt; $model-&gt;getContractors(),
      'language' =&gt; 'en',
      'options' =&gt; ['placeholder' =&gt; '-- Select company --'],
      'pluginOptions' =&gt; [
          'allowClear' =&gt; true,
          'multiple' =&gt; true,
      ],
      'showToggleAll' =&gt; false
  
  ]) ?&gt;
  </code></pre>
  
  <p>It wont validate or save, because of read-only property payers. I tried to use different property in $form->field($model, 'payer'... (instead of payers), then validation works and even saving works, but trouble is, that editing have no preselected values of that model, because they are in model->payers. And i have no idea, what iam supposed to pass here instead of this relationship object (or property of model in general). </p>
  
  <p>Maybe iam plainly blind, but in manual there is a lot of information about getting data from db, but almost no info about saving.
  (btw. i saw this post: <a href="https://stackoverflow.com/questions/35397138/yii2-invalid-call-setting-read-only-property">Yii2 Invalid Call: Setting read-only property</a> - but that didnt give me any new piece of information at all).</p>
  
  <p>Is my form design wrong, or model design (Meaning i should just create form field using two models)? Thanks</p>