2010-05-25 66 views
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完成,但我发现文档不清楚。

回答

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); 

主义应该使用refclass执行内部连接为您服务。

7

更改findByloc_id()findByLocId()。该方法被魔术__call()捕获。