Yii Framework Forum: How To Save And Update Field In A Join Table? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Save And Update Field In A Join Table? Rate Topic: -----

#1 User is offline   Double A 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 05-February 13

Posted 10 February 2013 - 06:26 AM

Hi,
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!
thanks
0

#2 User is offline   Coksnuss 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 14-May 09

Posted 10 February 2013 - 01:51 PM

View PostDouble A, on 10 February 2013 - 06:26 AM, said:

Hi,
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!
thanks


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

protected/models/Property.php:
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.
0

#3 User is offline   Double A 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 05-February 13

Posted 11 February 2013 - 12:02 AM

View PostCoksnuss, on 10 February 2013 - 01:51 PM, said:

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

protected/models/Property.php:
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:
http://www.yiiframew...-checkbox-list/
hopefully i will do this thing do and post my solution here to help others.
thanks again
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users