Yii dynamic forms

Branch Table
branch_id(pk)
branch_name

department table
depart_id
depart_name
branch_id(fk)

I want to assign foreign key (branch_id) of department table. in departmentController create action so that when I create department it will fill the FK
I hava a tried
$modeldepart->depart_id = $modelBranch->branch_id; but not working