Cake 3.4
Articles belongTo Categories
Users can delete categories so, sometimes, articles no longer belong to any category.
How can I find all orphan articles ?
I tried :
$categories = $this->Articles->Categories->find()
->select(‘Categories.id’, ‘Categories.name’)
->toList()
;
then :
$query = $this->Articles->find()
->select([‘Articles.id’, ‘Articles.category_id’, ‘Articles.name’, ‘Articles.published’])
->where([‘Articles.category_id not in’ => $categories])
->order([‘Articles.name’ => ‘ASC’])
->contain([‘Categories’])
;
Thank you for your answer.
In fact, I need to do this in pre prod mode because the webmaster of my client is not sure of the site map he wants and he tries different options.
Of course, this will not be possible in production mode.
In fact, my problem was with this line :
->contain([‘Categories’])
as there is of course no category to be contained !