1

我在选择带有教义的数据子集时遇到问题。

我有 3 张桌子

位置 联系 Contact_location

联系人和位置表包含一个名称和一个 ID,另一个表只包含 ID。例如:

Location
 loc_id: 1
 name: detroit
Contact
 contact_id: 1
 name: Mike
Contact_location
 loc_id: 1
 contact_id: 1

在原则上,位置表和联系人表之间存在多对多关系,其中contact_location 作为ref_class。

我想做的是在我的位置页面上找到所有联系人,例如 loc_id = 1。

我试过:

 $this->installedbases = Doctrine::getTable('contact')->findByloc_id(1);

希望教义会看到这种关系并得到它,但它没有。

如何在相关的相关表格中进行教义搜索?我读到它可以使用 Findby 完成,但我发现文档不清楚。

4

2 回答 2

7

更改findByloc_id()findByLocId()。方法是被魔法捕捉到__call()

于 2010-05-25T12:40:26.727 回答
2

在你的表类上添加一个方法:

class ContactTable extends Doctrine_Table
{
  public function findByLocationId($id)
  {
    return self::createQuery("c")
      ->innerJoin("c.Location l")
      ->where("l.loc_id = ?", $id)
      ->execute();
  }
}

然后按如下方式调用它:

$loc_id = 1;
$result = Doctrine::getTable("Contact")->findByLocationId($loc_id);

Doctrine 应该使用 refclass 为您执行内部连接。

于 2010-05-25T12:34:46.370 回答