Bare with me as I’m not the best at articulating…
I have overridden the fields function like so in models/CallerIdentity.php.
public function fields()
{
$fields = parent::fields();
$fields[] = 'ehadata';
return $fields;
}
CallerIdentity has relation set like so:
public function getEhadata()
{
return $this->hasMany(EHAData::className(), ['cidref' => 'cidref']);
}
Controller class is NumbersController. So now if I fire off GET request to api.dev/v1/numbers the response is like so, which is what I was aiming for.
{
"cidref": 411,
"custref": 178,
"caller_id": "978378478",
"expiry": "2021-06-27",
"conf_call": "n",
"type": "F",
"redirect": null,
"destination": "help@help.com",
"status": 1,
"start_date": "2010-09-17",
"last_polled": "2012-12-07 08:30:02",
"ehadata": [
{
"status": 0,
"name": "Blah ",
"bussuffix": "Ltd",
"premesis": "Blah House",
"thoroughfare": "Blah Road",
"locality": "Manchester",
"postcode": "T56 T4G"
}
]
},
Come to writing tests for the endpoint and I cannot access any of the ehadata fields.
I can do:
$I->seeResponseJsonMatchesJsonPath('$[0].ehadata');
var_dump($fields) output
array (size=12)
'cidref' => string 'cidref' (length=6)
'custref' => string 'custref' (length=7)
'caller_id' => string 'caller_id' (length=9)
'expiry' => string 'expiry' (length=6)
'conf_call' => string 'conf_call' (length=9)
'type' => string 'type' (length=4)
'redirect' => string 'redirect' (length=<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />
'destination' => string 'destination' (length=11)
'status' => string 'status' (length=6)
'start_date' => string 'start_date' (length=10)
'last_polled' => string 'last_polled' (length=11)
1 => string 'ehadata' (length=7)
To check that the array is there but I can’t check any of the individual fields, no matter what I try. This made me think about when I come to write the update function, how can I access/manipulate the fields?
Any help would be massively appreciated.