I've been having a look at phalcon as an alternative to a laravel project that I'm running. It's mainly a REST api. I'm trying to figure out how to include relationships in a json response for models.
For example, if I had 2 models, set up like below:
class Clients extends \Phalcon\Mvc\Model
{
public function initialize() {
$this->hasMany('clientid','Contacts','clientid')
}
}
class Contacts extends \Phalcon\Mvc\Model {
public function initialize() {
$this->belongsTo('clientid','Clients','clientid')
}
}
And I did a:
$clients = Client::find();
return json_encode($clients->toArray());
How would I get it to automatically include the contacts?
I need to output to be something like this:
[{ clientid:'1111', contacts:[ { contactid:111 } ] }];
Many thanks!