0

I have a DepartmentsWokplans Model that belongs to only one CoprprateWorkPlan. The CorporateWorkPlan Model has many CorporateStrategicObjectives. Using a DepartmentWorkplanId, I'm able to the CoprporateStatergicObjectives using the code I have shared Below but only the Ids. My problem is how do I get more details about the CoprporateStatergicObjectives (Eg Description, ETC) which are stored in another table using the Id's that I have?

DepartmentWorkPlansModel = DepartmentWorkPlans::findOne($DepartmentWorkPlanId); 

$CorporateObjectives = $DepartmentWorkPlansModel->corporateWorkPlan->corporateStrategicObjectives;

//How Do I get more Details about the CorporateObjectives?

Results I'm getting when I Print_r($CorporateObjectives)

Array
(
    [0] => common\models\CorporateStrategicObjectives Object
        (
            [_attributes:yii\db\BaseActiveRecord:private] => Array
                (
                    [CorporateObjectiveId] => 1
                    [CorporateWorkPlanId] => 5
                    [StrategicObjectiveId] => 5
                )

            [_oldAttributes:yii\db\BaseActiveRecord:private] => Array
                (
                    [CorporateObjectiveId] => 1
                    [CorporateWorkPlanId] => 5
                    [StrategicObjectiveId] => 5
                )

            [_related:yii\db\BaseActiveRecord:private] => Array
                (
                )

            [_relationsDependencies:yii\db\BaseActiveRecord:private] => Array
                (
                )

            [_errors:yii\base\Model:private] => 
            [_validators:yii\base\Model:private] => 
            [_scenario:yii\base\Model:private] => default
            [_events:yii\base\Component:private] => Array
                (
                )

            [_eventWildcards:yii\base\Component:private] => Array
                (
                )

            [_behaviors:yii\base\Component:private] => Array
                (
                )

        )
  • add relation the the CorporateObjectives model https://www.yiiframework.com/doc/guide/2.0/en/db-active-record#relational-data – ScaisEdge Feb 17 '21 at 20:36
  • I've already Done that, here is how I've done it public function getStrategicObjective() { return $this->hasOne(StrategicObjectives::className(), ['StrategicObjectiveId' => 'StrategicObjectiveId']); } – Kinyua James Feb 17 '21 at 20:54
  • where are store the data you are looking for (Eg Description, ETC) ??? in which model ..?? – ScaisEdge Feb 17 '21 at 20:56
  • In the StrategicObjectives Model – Kinyua James Feb 17 '21 at 21:00
  • then how StrategicObjectives is related with CorporateObjectives ?? .. you have some function in your CorporateObjectives with a hasOne relation with StrategicObjectives ??? .. in you print_r you have the id but not a relation with StrategicObjectives – ScaisEdge Feb 17 '21 at 21:07
  • The getStrategicObjective() is the relationship between the 2 tables. From the print_r() I'm only getting the StrategicObjectiveId but I also need the Description there. How do I add it there? – Kinyua James Feb 17 '21 at 21:19

0 Answers0