Getting An Id (Query Builder)

I have a form where I collect “job” data from to insert a new row into a DB table. Two fields are then used to recover a store id from a separate DB table. I’m just wondering if there’s a better way to do this kind of stuff. Here’s my bit of code, it just feels like there’s a better code for this:

Job controller:




            $model->store_id = $test = Job::getStoreId($model->account, $model->store_number);




Job model (query to retrieve the ID):

    public static function getStoreId($account, $number)


        $_id = Yii::app()->db->createCommand()



                ->where('account = :ui_account AND number = :ui_store_number', array(

                    ':ui_account' => $account,

                    ':ui_store_number'  => $number


        return $_id['id'];


Hi my friend

May you can do it by Relational Active Record but is depended by the complication of your Ar schema