title: Relational attribute in Yii2 form
body: <p>I am trying to get to figure out the proper way of handling a form receiving relational data in Yii2. I haven't been able to find any good examples of this. I have 2 models Sets and SetsIntensity, every Set may have one SetsIntensity associated with it. I'm am trying to make a form where you can input both at the same time. I'm not sure how to handle getting the input for a particular field 'intensity' in SetsIntensity.</p>
  
  <p>Where</p>
  
  <pre><code>$model = new \app\models\Sets();
  </code></pre>
  
  <p>If I put it in the field like this client validation won't work and the attribute name is ambiguous and saving becomes difficult</p>
  
  <pre><code>&lt;?= $form-&gt;field($model, 'lift_id_fk') ?&gt;
  &lt;?= $form-&gt;field($model, 'reps') ?&gt;
  &lt;?= $form-&gt;field($model, 'sets') ?&gt;
  &lt;?= $form-&gt;field($model, 'type') ?&gt;
  &lt;?= $form-&gt;field($model, 'setsintensity') ?&gt;
  </code></pre>
  
  <p>I would like to do something like this but I get an error if I do</p>
  
  <pre><code>&lt;?= $form-&gt;field($model, 'setsintensity.intensity') ?&gt;
  Exception (Unknown Property) 'yii\base\UnknownPropertyException' with message 'Getting unknown property: app\models\Sets::setsintensity.intensity'
  </code></pre>
  
  <p>I could do make another object in the controller <code>$setsintensity = new Setsintensity();</code> but I feel this is a cumbersome solution and probably not good practice especially for handling multiple relations</p>
  
  <pre><code>&lt;?= $form-&gt;field($setsintensity, 'intensity') ?&gt;
  </code></pre>
  
  <p>relevant code from SetsModel</p>
  
  <pre><code>class Sets extends \yii\db\ActiveRecord
  {
  
      public function scenarios() {
          $scenarios = parent::scenarios();
          $scenarios['program'] = ['lift_id_fk', 'reps', 'sets', 'type', 'intensity'];
          return $scenarios;
      }
  
  public function rules()
  {
      return [
          [['lift_id_fk'], 'required'],
          [['lift_id_fk', 'reps', 'sets','setsintensity'], 'integer'],
          [['type'], 'string', 'max' =&gt; 1],
          ['intensity', 'safe', 'on'=&gt;'program']
      ];
  }
  public function getSetsintensity()
  {
      return $this-&gt;hasOne(Setsintensity::className(), ['sets_id_fk' =&gt; 'sets_id_pk']);
  }
  </code></pre>
  
  <p>SetsIntensity Model</p>
  
  <pre><code>class Setsintensity extends \yii\db\ActiveRecord
  {
  
      public static function tableName()
      {
          return 'setsintensity';
      }
  
      public function rules()
      {
          return [
              [['sets_id_fk', 'intensity', 'ref_set'], 'required'],
              [['sets_id_fk', 'intensity', 'ref_set'], 'integer']
          ];
      }
  
      public function getSetsIdFk()
      {
          return $this-&gt;hasOne(Sets::className(), ['sets_id_pk' =&gt; 'sets_id_fk']);
      }
  }
  </code></pre>
  
  <p>I was also thinking maybe I could put in a <code>hasOne()</code> relation for the specific attribute 'intensity' in 'Sets'</p>