Cakephp 4 - Error with association

In my view i get the following message

# Argument 1 passed to Cake\ORM\Entity::get() must be of the type string, int given, called in C:\xampp\htdocs\myproject\vendor\cakephp\cakephp\src\Datasource\EntityTrait.php on line 604

           $this->hasMany('Children', [
                'className' => 'Categories',
                'foreignKey' => 'parent_id',
            $this->belongsTo('Parent', [
                'className' => 'Categories',
                'foreignKey' => 'parent_id',


       $this->paginate = [
        $categories = $this->paginate($this->Categories);                


Thanks for any help.

Can you give DB structure of Parent and Children Table with Data Type?

This is my table database:
id int(11) NOT NULL,
slug varchar(255) NOT NULL,
parent_id int(11) NOT NULL,
description varchar(50) NOT NULL,
modified datetime NOT NULL,
created datetime NOT NULL
i have the this record on database:
(1, ‘test0’, 0, ‘Catalogo’, ‘2020-10-19 01:46:09’, ‘2020-10-18 23:50:56’),
(2, ‘test1’, 0, ‘Usado’, ‘2020-10-19 01:46:17’, ‘2020-10-19 01:29:54’),
(3, ‘test01’, 1, ‘Motocultivador’, ‘2020-10-20 01:56:55’, ‘2020-10-20 01:56:55’);
I can retrieve children without error but not the parent.

I may be way off base (early morning here) but shouldn’t this be: -

$this->belongsTo('Parent', [
                'className' => 'Categories',
                'foreignKey' => 'id',

id not parent_id as the key for the parent from the the child is the primary.
This is just a surface look, so educated guess only!

I found the problem is in my view, thank for your help, I used the wrong field name
instead of

@Jawfin I thought that relationship looked hinky too. But I couldn’t get my brain to engage with an answer. I wonder if this will be a lurking bug for @mokiwaa or if we’re both thinking about it wrong.