0

I have a field in my form 'update_job' named as 'job_category',which is a dropdownlist and has been stored in main table as category_id,and the table is related to another table 'category'.

My first question is how to write the joint query to get the category as well:I have written code to get all data and it works fine:but how to write a join query to get the category as well?

    //code//
        public function actionDisplayJob()
        {
                if (isset($_GET['id'])) {
                $id = $_GET['id'];
            }

             $model = DisplayJob::model()->find(array(
                'select' => array('posted_by', 'title', 'key_skills'), "condition" => "id=$id"
            ));

            $params = array('model' => $model);
            $this->render('update', $params);
        }

Second,What should I do to keep data selected in dropdown list from database while editng the data?

tereško
  • 58,060
  • 25
  • 98
  • 150
saji
  • 201
  • 1
  • 5
  • 19

1 Answers1

0

You can set relations in your model. Assuming you have done this, you can use 'with' to join the related model (tabel):

$model = DisplayJob::model()->with('category')->find(array(
       'select' => array('posted_by', 'title', 'key_skills'), "condition" => "id=$id"
));

More information about using relations you can find here: http://www.yiiframework.com/doc/guide/1.1/en/database.arr

davey
  • 1,801
  • 2
  • 17
  • 22