推进 - 过滤多对多关系

时间:2015-09-02 11:49:25

标签: many-to-many relationship propel

我尝试使用Propel并且没有成功过滤多对多关系

在此处,找到 schema.xml

<?xml version="1.0" encoding="UTF-8"?>
<database defaultIdMethod="native" name="flash">
  <table name="demand">
    <column name="id" type="INTEGER" primaryKey="true" autoIncrement="true" required="true" />
    <column name="label" type="VARCHAR" size="90" required="true" />
    <column name="description" type="LONGVARCHAR" required="true" />
  </table>
  <table name="customer">
    <column name="id" type="SMALLINT" primaryKey="true" autoIncrement="true" required="true" />
    <column name="name" type="VARCHAR" size="32" required="true" />
    <column name="service_id" type="SMALLINT" required="true" />
    <foreign-key name="fk_customer_service" foreignTable="service">
      <reference local="service_id" foreign="id"/>
    </foreign-key>
  </table>
  <table name="service">
    <column name="id" type="SMALLINT" primaryKey="true" autoIncrement="true" required="true" />
    <column name="label" type="VARCHAR" size="4" />
  </table>

  <table name="demand_customer" isCrossRef="true">
    <column name="demand_id" type="INTEGER" primaryKey="true" required="true" />
    <column name="customer_id" type="SMALLINT" primaryKey="true" required="true" />
    <foreign-key name="fk_demand_customer_demand" foreignTable="demand" onDelete="CASCADE">
      <reference local="demand_id" foreign="id"/>
    </foreign-key>
    <foreign-key name="fk_demand_customer_customer" foreignTable="customer" onDelete="CASCADE">
      <reference local="customer_id" foreign="id"/>
    </foreign-key>
  </table>
</database>

我想检索附加客户服务的所有要求等于3 (例如)。根据以下数据,我只需需求ID号为

你能帮帮我吗?

数据示例:

    demand
-------------------------------
id  |   label   |   description
-------------------------------
1       test1       desc1
2       test2       desc2


customer
------------------------------
id  |   name    |   service_id
------------------------------
1       name1       1
2       name2       3
3       name2       2


service
-------------
id  |   label
-------------
1       service1
2       service2
3       service3


demand_customer
---------------------------
demand_id   |   customer_id
---------------------------
1               1
2               1
2               2

1 个答案:

答案 0 :(得分:0)

我发现了如何做到这一点:

$demands = DemandQuery::create()
->useDemandCustomerQuery()
    ->useCustomerQuery()
        ->filterByServiceId(getSessionValue('service'))
    ->endUse()
->endUse()
->find();