2016-06-12 3 views
0

は基本的に、私はNを持っています。 Plans and SusciationプライマリキーはこのN:M関係の主キーであり、このN:M関係も「価格」属性を有する。 私は、この表の価格の属性を更新する必要があるので、私はPropelのことで生成されたクラスでそれにアクセスする方法を見つけ出すことはできません。 私が見てきたように、PlanクラスとSubscriptionクラスには、私が必要なことをするための方法がないようです。私はPropelの上にいくつかのものをコーディングする必要がある場合があります、私はそのことを考えていたPropelによって生成されたCrossRefテーブルのプライマリキー以外の値にどのようにアクセスできますか? (「計画」と「サブスクリプション」テーブル間の)Mの関係:

これは、これらのツリーの関係(計画、サブスクリプションおよびそのCrossRefの)宣言されている私のschema.xmlの一部である

<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のドキュメントに研究してきましたが、彼らはちょうどこの特定のケース扱いません:それは夜(実際には夜明け - 朝)だけの問題だった

Blog: Many-to-many Relationships: Check!

Basic Relationships

答えて

0

をこれを再調査してください。

はPropelがメソッドを生成したオブジェクトを更新する方法があります。連想配列では、列の値が大文字(P米)で始まること注意:私はちょうどそのプライマリキー

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

重要で、私のObjectQuery(PlansSubscriptionsQuery)をフィルタリングする必要がありました。これまで私が見ることができたように、これは内部的にPropelがこのようにして動作するためです。あなたの列の名前が2つ以上の単語で構成されている場合、それは最初の文字の単語capilatizedになります。 I D P米やM Y S UPER wesome C N olumn雨

I found a question here that made me realize of this、私のschema.xmlファイルはオールライトだったが、私は列にアクセスしようとしていましたschema.xmlファイル(price、id_plan、id_subscriptionなど)に下線付きの名前が設定されていますが、これは正しくありません。

私はこれが誰かを助けてくれることを願っています。

関連する問題