0

Doctrine 总是在查询中包含一个 ID 列,例如:

 $new_fees = Doctrine::getTable('Stats')->createQuery('s')
  ->select('s.sid')->where('s.uid = ?', $this->uid)
  ->andWhere('s.operation = ?', PPOperationType::FEE_PAID_BY_REFERRED_OWNER)
  ->andWhere('s.created_at > ?', $lastwd)
  ->groupBy('s.sid')->execute();

不起作用,因为 s.id 包括在内(我没有要求教义)。如何摆脱该 id 列?必须在这里使用原始 SQL 会扼杀教义的用处。

4

2 回答 2

2

您必须将该表的某些列设置为 setTableDefinition 中的主要列,以便学说不使用默认主要作为 id。假设您的 sid 是您的实际主键.. 那么...

    public function setTableDefinition(){
    ....
    $this->hasColumn('sid', 'decimal', 2, array(
                 'type' => 'decimal',
                 'length' => 2,
                 'unsigned' => 0,
                 'primary' => true,
                 'default' => '0',
                 'notnull' => true,
                 'autoincrement' => false,
                 ));
    }

请注意'primary' => true,这会阻止学说使用 id 作为默认主键(即使它甚至没有在表定义文件中定义。

于 2012-04-27T17:23:05.550 回答
1

这不是最漂亮的解决方案,但您可以在 Doctrine_Query 上调用 isSubquery(true) 来删除主键,在您的情况下为 s.id。

http://www.doctrine-project.org/api/orm/1.2/doctrine/doctrine_query.html#isSubquery()

于 2011-02-11T22:59:01.673 回答