如何选择原则1.2中没有关系记录的表格记录



如何使用条令1.2查询选择所有没有关系记录的表记录?

我尝试过这种事情(下面),但它告诉我没有t关系,可能是因为我在关系表中设置了FK关系?看起来这应该很容易,但无法理解。查看了子查询,但我无法理解这是否正确。谢谢

     $q = Doctrine_Query::create()
    ->from('Table t')
    ->leftJoin('t.Relations r')
     ->where('t.user_id = ?',$userId)
     ->andWhere('t.Relations IS NULL')
        return $q->execute();

简化得多的模式:

Table:
  columns:    
    id:
      type:             integer
      notnull:          true
    user_id:
      type:             integer
      notnull:          true
  relations:
    User:
      class:            User
      foreign:          id
      local:            user_id
      foreignAlias:     Users

Relation:
  columns:    
    table_id:
      type:             integer
      notnull:          true
  relations:
    Table:
      class:            Table
      foreign:          id
      local:            table_id
      foreignAlias:     Relations

在不知道您的错误消息的情况下,我只是猜测,但错误可能在您的andWhere(..)语句中。表t没有属性Relation,而是要检查表r:

$q = Doctrine_Query::create()
    ->from('Table t')
    ->leftJoin('t.Relations r')
    ->where('t.user_id = ?',$userId)
    ->andWhere('r.table_id IS NULL')
return $q->execute();

最新更新