I am trying to make the relationship between the tables I read The documentations in cakephp3, and tons of post in stackoverflow, and still can’t get any result. I have two tables.
category (id, name, published, created, modified)
portfolio (id, category_id, name, created, modified)
I want to display every element of portofolio with category like this:
Category Cars
* element 1: Bmw
* element 2: Audi
* element 3: Ford
How can i make this relation and display?
In categories model I write :
$this->belongsTo('Portfolios', [
'foreignKey' => 'id'
]);
And this is the query:
$portfolios_category = $this->Categories->find()
->contain(['Portfolios'])
->where(['Categories.published' => 1])
->order(['Categories.created' => 'desc'])
->all();