转化为学说

时间:2012-07-23 11:35:36

标签: mysql doctrine doctrine-1.2

SELECT id, forename, surname, created 
FROM name n 
WHERE created = (SELECT MAX(created) 
                          FROM name 
                          GROUP BY id 
                          HAVING id = n.id);

的schema.yml:

    id:
      type: integer(4)
      fixed: false
      unsigned: true
      primary: true
      autoincrement: true
  lcreated:
      type: timestamp(25)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
  forname/surname:
      type: integer(4)
      fixed: false
      unsigned: true
      primary: false
      notnull: true
      autoincrement: false

我确实有一个forname和surname的额外表格。

如何将其转换为学说1.2?

1 个答案:

答案 0 :(得分:0)

试试这个:

$query = Doctrine_Query::create()
  ->from('Name m')
  ->where('m.created = (SELECT MAX(gn.created) 
                          FROM Name gn
                          GROUP BY gn.id 
                          HAVING m.id = gn.id)');

Link to the documentation