0

All, I need to get a table value based on the primary key from it table then I used that on the other table. I can ilustrate my question like this:

table a

  • id_a
  • att_a1
  • att_a2
  • att_a3
  • att_a4
  • att_a5

table b (dummy table)

  • id_a
  • id_c
  • percentage_a1
  • percentage_a2

table c (here i need to calculate my result)

  • id_c
  • att_c1 = att_a1*percentage_a1
  • att_c2 = att_a2*percentage_a2
  • att_c3 = att_c2+att_a4

How could I do that in Yii?

Any response pls Thx, my regards

Brett Gregson
  • 5,867
  • 3
  • 42
  • 60
  • where will the table's information be get from table c ? – Bàn Chân Trần Feb 25 '13 at 04:42
  • – Bàn Chân Trần - the table c attributes : att_c1 was the result of table a's attribute multiplying with the table b's attribute = att_a1 * percentage_a1, so that the table c would get the value by getting the information from table a and b. – user2105963 Feb 25 '13 at 14:00
  • -stu - i've trying to generate the model, controller for each table and crud generator just for the table a and c because the table b had composite pk which means i can't use gii to generate my crud. i modified my table c model relation with this : public function relations() { return array( //'kelayakan' => array(self::BELONGS_TO, 'KelayakanUsaha', 'kelayakan_id'), 'tabelBs' => array(self::HAS_MANY, 'tabelB', 'id_b'), 'tabelA' => array(self::HAS_MANY, 'tabelA', array('id_a'=>'id'),'through'=>'tabel_b'), ); } – user2105963 Feb 25 '13 at 16:17
  • what i wanna do and confused is how can i calculate the table c using the data from table a and multiply with table b (percentage) and save the result in table c. the percentage_a1 and percentage_a2 attributes from table b was depend on the data from table a and will be save in table c. i really don't know how to doing this using yii framework. thanks – user2105963 Feb 25 '13 at 16:25
  • sorry for my bad english :) – user2105963 Feb 25 '13 at 16:26

1 Answers1

0

There are a couple of things that you need to do. You need to establish a many to many relationship between the two tables inside the class of the middle table. You need to set has settings for each of the outer tables.

Follow these instructions:

http://www.yiiframework.com/doc/guide/1.1/en/database.arr

Jason G
  • 2,395
  • 2
  • 24
  • 34