title: Yii - When is MySQL CREATE VIEW invoked?
body: <p>I've been handed a Yii app to maintain and extend and I'm in the familiarizing process, mostly with Yii as I haven't used it before.</p>
  
  <p>The app uses MySQL views at a pretty large extent and many models are based on them rather than tables. </p>
  
  <p>What I cant figure out is, where/when does Yii invoke the ALTER VIEW statement in order to populate with data prior to performing the various actions?</p>
  
  <p>Here's an example:</p>
  
  <p>MySQL VIEW:</p>
  
  <pre><code>DELIMITER $$
  ALTER ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `my_db`.`vw_last30daysorders` AS 
  SELECT
    `d`.`OrderID` AS `OrderID`,
    COUNT(`d`.`PropertyID`) AS `cntprops`,
    `m`.`RequestID`   AS `RequestID`
  FROM (`my_db`.`orders_d` `d`
     JOIN `my_db`.`orders_m` `m`)
  WHERE ((`d`.`OrderID` = `m`.`OrderID`)
         AND (`m`.`OrderDate` BETWEEN(CURDATE() - INTERVAL 30 DAY)
              AND CURDATE()))
  GROUP BY `d`.`OrderID`$$
  DELIMITER ;
  </code></pre>
  
  <p>And the Yii Model class: </p>
  
  <pre><code>class VWLast30DaysOrders extends CActiveRecord
  {
      public static function model($className=__CLASS__)
      {
          return parent::model($className);
      }
  
      public function tableName()
      {
          return 'vw_last30daysorders';
      }
  
      public function rules()
      {
          return array(
              array('requestid', 'required'),
              array('requestid', 'numerical', 'integerOnly'=&gt;true),
              array('totreqs', 'length', 'max'=&gt;21),
              array('totreqsprops', 'length', 'max'=&gt;42),
              array('requestid, totreqs, totreqsprops', 'safe', 'on'=&gt;'search'),
          );
      }
  
      public function relations()
      {
          return array();
      }
  
      public function attributeLabels()
      {
          return array(
              'requestid' =&gt; 'Requestid',
              'totreqs' =&gt; 'Totreqs',
              'totreqsprops' =&gt; 'Totreqsprops',
          );
      }
      public function search()
      {
          $criteria=new CDbCriteria;
          $criteria-&gt;compare('requestid',$this-&gt;requestid);
          $criteria-&gt;compare('totreqs',$this-&gt;totreqs,true);
          $criteria-&gt;compare('totreqsprops',$this-&gt;totreqsprops,true);
          return new CActiveDataProvider($this, array('criteria'=&gt;$criteria));
      }
  }
  </code></pre>
  
  <p>I've checked the DB for triggers that could possibly be adding data to the view but failed to find any.</p>