Basically, I have a N:M relationship (between "plans" and "subscriptions" tables). Plans and Suscriptions primary-keys are the primary-keys of this N:M relationship, this N:M relationship also has a "price" attribute. Since I need to update the price attribute on this table, I cannot figure out how to access to it with the classes generated by Propel. As I can see, it seems that Plan and Subscription classes have not any method that allows me to do what I need.
This is the part of my schema.xml where are declared these tree relationships (plans, subscriptions and their 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>
I was thinking of that I might have to code some stuff on Propel generated classes for doing it, but I can't figure out how to access a row of this table by its primary-keys either.
I've researched on Propel's documentation but they just don't treat this particular case:
It was just matter of a night (actually a dawn-morning) of good sleep and re-research this.
There is way to update objects with Propel generated methods. I just had to filter my ObjectQuery (PlansSubscriptionsQuery) by its primaries keys
// 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;
IMPORTANT: Notice that in the associative array, column value begins with a capital letter (Price). As far I could see, this is because internally Propel works in this way with this. In case your column's name is made up by two or more words it's going to be each first letter word capilatized: e.g. IdPrice or MySuperAwesomeColumnName
I found a question here that made me realize of this, my schema.xml file was allright but I was trying to access the column with the underscored name set up in the schema.xml file (price, id_plan, id_subscription and so on) which is not correct.
I hope this helps someone.