Propel - 具有多对多关系的过滤器

Propel - Filter with many-to-many relationship

我尝试使用 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 编号 2

你能帮帮我吗?

数据示例:

    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

我找到了如何做到这一点:

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