Cakephp 3不检索关联模型的记录

Cakephp 3不检索关联模型的记录,php,cakephp,cakephp-3.x,cakephp-3.4,Php,Cakephp,Cakephp 3.x,Cakephp 3.4,我的学校模型与我的属性模型有一个many-to-many关系,属性模型由attribute\u-school表连接。 在cron作业的Shell文件夹中,我的主要功能包括: $schoolsRaw = TableRegistry::get('Schools'); $schools = $schoolsRaw->find('all', [ 'fields' => [ 'Schools.name', 'Schools.logo',

我的学校模型与我的属性模型有一个
many-to-many
关系,属性模型由
attribute\u-school
表连接。 在cron作业的Shell文件夹中,我的主要功能包括:

$schoolsRaw = TableRegistry::get('Schools');

$schools = $schoolsRaw->find('all', [
    'fields' => [
        'Schools.name',
        'Schools.logo',
        'Schools.discount'
    ],    
    'contain' => [
        'Users'=> [
            'fields' => [
                'Users.first_name',
                'Users.last_name',
                'Users.email',
                'Users.title'
            ]
        ],
        'Attributes' => [
            'fields' => [
                'Attributes.model'
            ]
        ]
    ]
]);

echo debug(json_encode($schools , JSON_PRETTY_PRINT));
上面的echo命令不断为学校记录的所有实例生成空值,如下所示:

{
    "name": "Genesis School",
    "logo": "badges\/genesis.jpg",
    "discount": "Not Stated",
    "attributes": [],
    "user": {
        "first_name": "xxxxx",
        "last_name": "yyyyy",
        "email": "mynane@yahoo.co.uk",
        "title": "Ms"
    }
我的型号

//schools
public function initialize(array $config)
{
    parent::initialize($config);

    $this->setTable('schools');
    $this->setDisplayField('name');
    $this->setPrimaryKey('id');

    $this->belongsTo('Users', [
        'foreignKey' => 'user_id',
        'joinType' => 'INNER'
    ]);
    $this->belongsToMany('Attributes', [
        'foreignKey' => 'school_id',
        'targetForeignKey' => 'attribute_id',
        'joinTable' => 'attributes_schools'
    ]);
}

// attributes model
public function initialize(array $config)
{
    parent::initialize($config);

    $this->setTable('attributes');
    $this->setDisplayField('name');

    $this->belongsToMany('Schools', [
        'foreignKey' => 'attribute_id',
        'targetForeignKey' => 'school_id',
        'joinTable' => 'attributes_schools'
    ]);
}

// join table
public function initialize(array $config)
{
    parent::initialize($config);
    $this->primaryKey('id');
    $this->setTable('attributes_schools');

    $this->belongsTo('Schools', [
        'foreignKey' => 'school_id',
        'joinType' => 'INNER'
    ]);
    $this->belongsTo('Attributes', [
        'foreignKey' => 'attribute_id',
        'joinType' => 'INNER'
    ]);
}

这是CakePHP3.4,我不知道为什么它不获取属性记录,也不记录错误。请帮助

是否有任何相关属性?检查表中的键。还要检查生成的SQL查询。如果没有例外,绑定通常是正确的。另外,为什么不在旧的数组符号上使用查询生成器呢?是否有任何相关的属性?检查表中的键。还要检查生成的SQL查询。如果没有例外,绑定通常是正确的。另外,为什么不在旧的数组表示法上使用查询生成器呢?