title: Table view OR temporary table in Doctrine + symfony 2.3
body: <p>I was trying to implement bayesian average logic in doctrine and symfony.</p>
  
  <p>I have basic native Mysql query like this:</p>
  
  <pre><code>    Create View `ratings` AS
  SELECT
      restaurant_id,
      (SELECT count(restaurant_id) FROM ratings) / (SELECT count(DISTINCT restaurant_id) FROM ratings) AS avg_num_votes,
      (SELECT avg(rating) FROM ratings) AS avg_rating,
      count(restaurant_id) as this_num_votes,
      avg(rating) as this_rating
  FROM
      ratings
  GROUP BY 
      restaurant_id
  
  
  SELECT 
      restaurant_id, 
      ((avg_num_votes * avg_rating) + (this_num_votes * this_rating)) / (avg_num_votes + this_num_votes) as real_rating 
  FROM `ratings`
  </code></pre>
  
  <p>This query creates table view from where we are retrieving records.</p>
  
  <p>From some documents I came to know that we can't create view in Doctrine. So another option is to create temporary table. How we can create temp table with different structure.</p>
  
  <p>Referring : <a href="http://shout.setfive.com/2013/11/21/doctrine2-using-resultsetmapping-and-mysql-temporary-tables/" rel="nofollow">http://shout.setfive.com/2013/11/21/doctrine2-using-resultsetmapping-and-mysql-temporary-tables/</a></p>
  
  <pre><code>// Add the field info for each column/field       
    foreach( $classMetadata-&gt;fieldMappings as $id =&gt; $obj ){
      $rsm-&gt;addFieldResult('u', $obj["columnName"], $obj["fieldName"]); 
      // I want to crate new fields to store avg rating etc.
    } 
  </code></pre>
  
  <p>How we can implement this in Doctrine and Symfony?</p>