【问题标题】:doctrine findby relation教义 findby 关系
【发布时间】:2010-05-25 10:46:24
【问题描述】:

我在使用原则选择数据子集时遇到问题。

我有 3 张桌子

位置 接触 联系方式

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

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

在原则上,location 和contact 表之间存在多对多关系,contact_location 作为 ref_class。

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

我试过了:

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

希望教义能看到并理解这种关系,但它没有。

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

【问题讨论】:

    标签: symfony1 doctrine orm foreign-key-relationship


    【解决方案1】:

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

    【讨论】:

      【解决方案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 为您执行内部连接。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-12-14
        • 1970-01-01
        • 1970-01-01
        • 2011-04-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-22
        相关资源
        最近更新 更多