HosipLan

Untitled

Feb 11th, 2012
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.16 KB | None | 0 0
  1.         $sql = "SELECT o.* FROM (
  2.                     SELECT MAX(o.actualAt) as actualAt, o.team_id, o.match_id, o.bookmaker_id FROM arb_match_odds o
  3.                     WHERE o.match_id = :matchId AND o.resultState = 'win' GROUP BY o.team_id, o.match_id, o.bookmaker_id
  4.                 ) newest
  5.                 INNER JOIN arb_match_odds o USING(actualAt, team_id, match_id, bookmaker_id)
  6.                 WHERE o.resultState = 'win'
  7.  
  8.                 UNION SELECT o.* FROM (
  9.                     SELECT MAX(o.actualAt) as actualAt, o.match_id, o.bookmaker_id FROM arb_match_odds o
  10.                     WHERE o.match_id = :matchId AND o.resultState = 'tie' GROUP BY o.team_id, o.match_id, o.bookmaker_id
  11.                 ) newest
  12.                 INNER JOIN arb_match_odds o USING(actualAt, match_id, bookmaker_id)
  13.                 WHERE o.resultState = 'tie' AND o.team_id IS NULL";
  14.  
  15.         $rsm = new ResultSetMapping;
  16.         $rsm->addEntityResult('Arb\Bet\MatchOdd', 'o');
  17.         $class = $this->doctrine->getClassMetadata('Arb\Bet\MatchOdd');
  18.         foreach ($class->getColumnNames() as $column) {
  19.             $rsm->addFieldResult('o', $column, $class->getFieldForColumn($column));
  20.         }
  21.  
  22.         $odds = $this->doctrine->getEntityManager()->createNativeQuery($sql, $rsm);
  23.         $odds->setParameter('matchId', $match->getId());
  24.  
  25.         dump($odds->getResult());
Advertisement
Add Comment
Please, Sign In to add comment