如何访问 Propel 生成的 CrossRef table 中的非主键值?

How can I access to a non primary key value in a CrossRef table generated by Propel?

基本上,我有一个 N:M 关系(在 "plans" 和 "subscriptions" table 之间)。 Plans 和 Suscriptions 主键是这个 N:M 关系的主键,这个 N:M 关系也有一个 "price" 属性。 因为我需要更新这个 table 的价格属性,所以我不知道如何使用 Propel 生成的 类 来访问它。 如我所见,似乎计划和订阅 类 没有任何方法可以让我做我需要的事情。

这是我的 schema.xml 的一部分,其中声明了这些树关系(计划、订阅及其 CrossRef)

<table name="subscriptions" phpName="Subscription">
    <column name="id_subscription" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
    <column name="name" type="varchar" required="true"/>
    <column name="description" type="longvarchar" required="true"/>
</table>

<table name="planes_subscriptions" isCrossRef="true">
    <column name="id_plan" type="integer" primaryKey="true"/>
    <column name="id_subscription" type="integer" primaryKey="true"/>
    <column name="price" type="real"/>

    <foreign-key foreignTable="planes" onDelete="CASCADE" onUpdate="CASCADE">
        <reference local="id_plan" foreign="id_plan"/>
    </foreign-key>
    <foreign-key foreignTable="subscriptions" onDelete="CASCADE" onUpdate="CASCADE">
        <reference local="id_subscription" foreign="id_subscription"/>
    </foreign-key>
</table>

<table name="planes" phpName="Plan">
    <column name="id_plan" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
    <column name="name" type="varchar" required="true"/>
    <column name="description" type="longvarchar" required="false"/>
    <column name="price" type="real" required="true"/>
</table>

我在想我可能必须在 Propel 上编写一些代码来生成 类 才能做到这一点,但我无法弄清楚如何通过其访问此 table 的一行主键。

我研究过 Propel 的文档,但他们就是不处理这种特殊情况:

Blog: Many-to-many Relationships: Check!

Basic Relationships

这只是一个晚上(实际上是黎明-早晨)的良好睡眠并重新研究它的问题。

可以使用 Propel 生成的方法更新对象。我只需要通过它的主键过滤我的 ObjectQuery (PlansSubscriptionsQuery)

// Create planSuscription query
$planSubscription = PlanesSubscriptionsQuery::create()->
// filter the query by plan and subscription ids
filterByIdPlan($idPlan)->filterByIdSubscription($idSuscripcion)->
// Magic comes here: an associative array with the value to update
update(array('Price' => $newSubscriptionPrice));
// Just checking amount of affected rows
echo $planSuscripcion;

重要提示: 请注意,在关联数组中,列值以大写字母开头 (Price)。据我所知,这是因为 Propel 在内部以这种方式工作。如果您的专栏名称由两个或多个单词组成,则每个首字母单词都会大写:例如IdPrice or MySuperAwesomeColumnName

I found a question here that made me realize of this,我的 schema.xml 文件没问题,但我试图访问 schema.xml 文件中设置的带下划线名称的列(价格,id_plan , id_subscription 等等)这是不正确的。

我希望这对某人有所帮助。