How To Save And Update Field In A Join Table?


i have the following scenario:

  1. Table: Property (property_id, name, address, city etc…)

  2. Table: Price (price_id, price_title(e.g. minimum, maximum etc…)

  3. Table: Property_Price(id, property_id, price_id, price_value, price_detail)

So, there could be multiple prices against property.

i want to ask how could i make a property creation form where list of prices with check boxes can display . so admin can check some box and give its value in textbox which could save in join table with property_id, price_id n price_value given from form.

i hope, i am pretty clear!


Hello Double A,

sadly there is no way I am aware of which lets you populate attributes within the interim table with new values.

I would basicly add a new property to the Property model called $prices


[CODE]class Property extends CActiveRecord


public $prices = array();


You may now collect several prices within your form, for a Property. You now need to manually fill that array with values by override the before*() and after*() methods accordingly. (e.g. Populate it in afterFind(), update/create/delete interim table entries within beforeSave() etc…).

You can then use this array within your formulas to render the checkboxes/textfields with the prices (and to collect new prices)

Maybe someone has a better solution for this. But right now, this is all i can think of.

hi Coksnuss,

thanks for your reply.

actually you are right. i already started work on this path as i found one more post describing nearly the same situation:

hopefully i will do this thing do and post my solution here to help others.

thanks again