Php 如何仅显示在Symfony 1.4中设置了foreignAlias的行

Php 如何仅显示在Symfony 1.4中设置了foreignAlias的行,php,doctrine,symfony-1.4,Php,Doctrine,Symfony 1.4,我有一个从三个表中提取的列表,部门、类型和用户 显示如下: Film student Jimmy Stewart faculty Cary Grant $this->departments = Doctrine_Core::getTable('Department') ->createQuery('a') ->leftJoin('a.Users p') ->groupBy('a.id')

我有一个从三个表中提取的列表,部门、类型和用户

显示如下:

Film 
student      Jimmy Stewart
faculty      Cary Grant
$this->departments = Doctrine_Core::getTable('Department')
        ->createQuery('a')
        ->leftJoin('a.Users p')
        ->groupBy('a.id')
        ->having('COUNT(a.id) > 0')
        ->orderBy('a.name ASC')
        ->execute();
来自actions.class.php

$this->departments = Doctrine_Core::getTable('Department')
        ->createQuery('a')
        ->orderBy('a.name')
        ->execute();
<?php foreach ($departments as $dept): ?>
      <tr>
        <?php check_for_id() ?>
        <td colspan="4" class="displayDept" valign="top"><?php echo $dept->getName() ?></td>
    </tr>
    <tr>
    <?php foreach ($dept->getUsers() as $user): ?>
    <tr>
      <td class="displayInfo" valign="top"><?php echo $user->getType() ?></td>
      <td class="displayInfo" valign="top"><a href="<?php echo $user->getUrl() ?>" target="_blank"><?php echo $user->getUrl() ?></a></td>
      <td class="displayInfo" valign="top"><?php echo simple_format_text($user->getDescription()) ?></td>
    </tr>
    <?php endforeach; ?>
   <?php endforeach; ?>
$this->departments = Doctrine_Query::create()
        ->select('d.id')
        ->from('Department d')
        ->leftJoin('d.Users u')
        ->groupBy('d.id')
        ->having('COUNT(u.id) > 0')
        ->orderBy('d.name ASC')
        ->execute();
indexSuccess.php

$this->departments = Doctrine_Core::getTable('Department')
        ->createQuery('a')
        ->orderBy('a.name')
        ->execute();
<?php foreach ($departments as $dept): ?>
      <tr>
        <?php check_for_id() ?>
        <td colspan="4" class="displayDept" valign="top"><?php echo $dept->getName() ?></td>
    </tr>
    <tr>
    <?php foreach ($dept->getUsers() as $user): ?>
    <tr>
      <td class="displayInfo" valign="top"><?php echo $user->getType() ?></td>
      <td class="displayInfo" valign="top"><a href="<?php echo $user->getUrl() ?>" target="_blank"><?php echo $user->getUrl() ?></a></td>
      <td class="displayInfo" valign="top"><?php echo simple_format_text($user->getDescription()) ?></td>
    </tr>
    <?php endforeach; ?>
   <?php endforeach; ?>
$this->departments = Doctrine_Query::create()
        ->select('d.id')
        ->from('Department d')
        ->leftJoin('d.Users u')
        ->groupBy('d.id')
        ->having('COUNT(u.id) > 0')
        ->orderBy('d.name ASC')
        ->execute();
我可以删除没有用户id的部门吗

更新

如果我要使用连接,我如何在操作中调用它?这就是我目前所处的位置,但我的迭代没有一个有效:

$this->departments = Doctrine_Core::getTable('Department')
        ->createQuery('a')
        ->leftJoin('a.Users p')
        ->orderBy('a.name ASC')
        ->execute();

但我不知道它能做什么。我可以理解传统php中的WHERE,但我不能遵循symfony语法。我是否已经接近了???

为什么不在查询中加入用户

更新

这是我头顶上的声音,但应该是这样的:

Film 
student      Jimmy Stewart
faculty      Cary Grant
$this->departments = Doctrine_Core::getTable('Department')
        ->createQuery('a')
        ->leftJoin('a.Users p')
        ->groupBy('a.id')
        ->having('COUNT(a.id) > 0')
        ->orderBy('a.name ASC')
        ->execute();

为什么不在查询中,加入用户部门呢

更新

这是我头顶上的声音,但应该是这样的:

Film 
student      Jimmy Stewart
faculty      Cary Grant
$this->departments = Doctrine_Core::getTable('Department')
        ->createQuery('a')
        ->leftJoin('a.Users p')
        ->groupBy('a.id')
        ->having('COUNT(a.id) > 0')
        ->orderBy('a.name ASC')
        ->execute();

Vlad说得对,我只是做了一些调整,想把它发布给其他人

这里是actions.class.php

$this->departments = Doctrine_Core::getTable('Department')
        ->createQuery('a')
        ->orderBy('a.name')
        ->execute();
<?php foreach ($departments as $dept): ?>
      <tr>
        <?php check_for_id() ?>
        <td colspan="4" class="displayDept" valign="top"><?php echo $dept->getName() ?></td>
    </tr>
    <tr>
    <?php foreach ($dept->getUsers() as $user): ?>
    <tr>
      <td class="displayInfo" valign="top"><?php echo $user->getType() ?></td>
      <td class="displayInfo" valign="top"><a href="<?php echo $user->getUrl() ?>" target="_blank"><?php echo $user->getUrl() ?></a></td>
      <td class="displayInfo" valign="top"><?php echo simple_format_text($user->getDescription()) ?></td>
    </tr>
    <?php endforeach; ?>
   <?php endforeach; ?>
$this->departments = Doctrine_Query::create()
        ->select('d.id')
        ->from('Department d')
        ->leftJoin('d.Users u')
        ->groupBy('d.id')
        ->having('COUNT(u.id) > 0')
        ->orderBy('d.name ASC')
        ->execute();
我还编辑了我的模式.yml

Department:
 actAs: { Timestampable: ~ }
 columns:
  id: { type: integer(4), primary: true, autoincrement: true }
  name: { type: string(255), notnull: true, unique: true }
 relations:
  User: {class: User, local: name, foreign: department_id, foreignAlias: Departments}

Type:
 actAs: { Timestampable: ~ }
 columns:
  id: { type: integer(4), primary: true, autoincrement: true }
  name: { type: string(255), notnull: true, unique: true }
  user_id: { type: integer(4) }

User:
 actAs: { Timestampable: ~ }
 columns:
  id: { type: integer(4), primary: true, autoincrement: true }
  firstname: { type: string(255), notnull: true }
  lastname: { type: string(255), notnull: true }
  email: { type: string(255), notnull: true, unique: true }
  department_id: { type: integer(4), notnull: true }
  type_id: { type: integer(4), notnull: true }
  url: { type: string(255), notnull:true }
  description: { type: string(4000) }
 relations:
  Department: { class: Department, local: department_id, foreign: id, foreignAlias: Users}
  Type: { class: Type, local: type_id, foreign: id, foreignAlias: Users }

这很有效。感谢您对别名字母的进一步解释。天还是有点雾,因为这些信似乎是刚写好的。我为部门选择了d,为用户选择了u,我不确定这是否有什么不同。谢谢@Vlad的帮助

Vlad做对了,我只是做了一些调整,想把它发布给其他人

这里是actions.class.php

$this->departments = Doctrine_Core::getTable('Department')
        ->createQuery('a')
        ->orderBy('a.name')
        ->execute();
<?php foreach ($departments as $dept): ?>
      <tr>
        <?php check_for_id() ?>
        <td colspan="4" class="displayDept" valign="top"><?php echo $dept->getName() ?></td>
    </tr>
    <tr>
    <?php foreach ($dept->getUsers() as $user): ?>
    <tr>
      <td class="displayInfo" valign="top"><?php echo $user->getType() ?></td>
      <td class="displayInfo" valign="top"><a href="<?php echo $user->getUrl() ?>" target="_blank"><?php echo $user->getUrl() ?></a></td>
      <td class="displayInfo" valign="top"><?php echo simple_format_text($user->getDescription()) ?></td>
    </tr>
    <?php endforeach; ?>
   <?php endforeach; ?>
$this->departments = Doctrine_Query::create()
        ->select('d.id')
        ->from('Department d')
        ->leftJoin('d.Users u')
        ->groupBy('d.id')
        ->having('COUNT(u.id) > 0')
        ->orderBy('d.name ASC')
        ->execute();
我还编辑了我的模式.yml

Department:
 actAs: { Timestampable: ~ }
 columns:
  id: { type: integer(4), primary: true, autoincrement: true }
  name: { type: string(255), notnull: true, unique: true }
 relations:
  User: {class: User, local: name, foreign: department_id, foreignAlias: Departments}

Type:
 actAs: { Timestampable: ~ }
 columns:
  id: { type: integer(4), primary: true, autoincrement: true }
  name: { type: string(255), notnull: true, unique: true }
  user_id: { type: integer(4) }

User:
 actAs: { Timestampable: ~ }
 columns:
  id: { type: integer(4), primary: true, autoincrement: true }
  firstname: { type: string(255), notnull: true }
  lastname: { type: string(255), notnull: true }
  email: { type: string(255), notnull: true, unique: true }
  department_id: { type: integer(4), notnull: true }
  type_id: { type: integer(4), notnull: true }
  url: { type: string(255), notnull:true }
  description: { type: string(4000) }
 relations:
  Department: { class: Department, local: department_id, foreign: id, foreignAlias: Users}
  Type: { class: Type, local: type_id, foreign: id, foreignAlias: Users }

这很有效。感谢您对别名字母的进一步解释。天还是有点雾,因为这些信似乎是刚写好的。我为部门选择了d,为用户选择了u,我不确定这是否有什么不同。谢谢@Vlad的帮助

这不会引发错误,但不会删除包含空用户数据的行。我想我不明白“a”和“p”代表什么。我是否应该编辑schema.yml?a是department表的别名,p是users表的别名。这不会引发错误,但不会删除用户数据为空的行。我想我不明白“a”和“p”代表什么。我应该编辑schema.yml吗?a是department表的别名,p是users表的别名。字母没有任何区别。部门的D很好。这封信没有什么区别。系里的D很好。