title: Unknown Method – when using set/get method on active record model property Yii2
body: <p>Lets say I have a table 'account' with below structure</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `account` (
    `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Id',
    `name` varchar(255) NOT NULL COMMENT 'Name',
    `index` int(11) NOT NULL COMMENT 'Index',
    `user_id` int(11) NOT NULL COMMENT 'UserID',
    PRIMARY KEY (`id`),
    KEY `user_id` (`user_id`)
  )
  </code></pre>
  
  <p>I have created a model 'Account' for that using gii.</p>
  
  <p>When I try create new account, I want <code>user_id</code> to be assigned from session</p>
  
  <p>So, In the controller, I tried like below.</p>
  
  <pre><code>$model = new Account();
  $model-&gt;**setUser_Id**(Yii::$app-&gt;user-&gt;getID());
  
  if ($model-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $model-&gt;save())
  </code></pre>
  
  <p>But, I don't write any <code>setUser_Id</code> method in Account model, since I assumed when I call set methods, it will automatically assign the property of ActiveRecord.</p>
  
  <p>But its throwing error. But it works fine when I try</p>
  
  <pre><code>$model-&gt;user_id = Yii::$app-&gt;user-&gt;getID();
  </code></pre>
  
  <p>As per documentation <a href="http://www.yiiframework.com/wiki/167/understanding-virtual-attributes-and-get-set-methods/" rel="nofollow">http://www.yiiframework.com/wiki/167/understanding-virtual-attributes-and-get-set-methods/</a>, 
  Note that the get/set functions can be called directly as functions (but requiring the usual function-call parentheses):</p>
  
  <pre><code>$x = $model-&gt;fullname;
  $x = $model-&gt;getFullname();        // same thing
  
  $model-&gt;active = 1;
  $model-&gt;setActive(1);              // same thing
  </code></pre>
  
  <p>Can you experts throw some light on this please?</p>