I have a table used for normalization called Sharing
the contents of the table are share_id, pr_id(patient record id) and doctor_id
I want to get the pr_id under a doctor
so I used this code...
$shareModel=Sharing::model()->findByAttributes(array('doctor_id'=>$doctor));
$share= $shareModel->pr_id;
then I changed my model from this:
$criteria->compare('pr_id',$this->pr_id);
into this:
$criteria->compare('pr_id',$share);
and it worked perfectly! However, when I decided to add more patient records under a single doctor.. it would still only display one record so I had to change the code to this
$shareModel=Sharing::model()->findAll(
array(
'condition'=>'doctor_id=:doctor_id',
'params' => array(':doctor_id' => $doctor)
)
);
whenever I try to test it using print_r($shareModel), I get the contents that I want but when I add this line
$share= $shareModel->pr_id;
I get a "Trying to get property of non-object" Error.
can anyone assist?
You will definitely get an error because findAll()
method returns array of objects.
It should be:
$share = $shareModel[0]->pr_id;
I would strongly recommend you to use model relations and dataprovider
.