Saving return values of function value to Database

I have created a function in my model PatientDetail.php.

This function is working well and returning the desired value, but I am not able to save the same in database.

public function getRoomCategory(){

     $model = \app\models\RoomCategory::find('id')


     ->innerjoin('patient_detail', ' = patient_detail.bed_type')               

     ->Where([''=> $this->id])->one();

     return $model;


I have a field/Column in the model as ‘room_category’ and I want to save the return value of the function getRoomCategory in the Database.

I have tried to create the function with the same name like getroom_category(){}, but then I am not getting any value in the form field in my _form.php

What is the best way to save the calculated value to the database? Thank for your valuable guidance.