cakephp 数组结果 [达到最大深度] [英] cakephp array results [maximum depth reached]

查看:14
本文介绍了cakephp 数组结果 [达到最大深度]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个模型.TeacherSubject 加入了 HABTM 定义了两种方式.一个老师可以教很多科目,一个科目可以由很多老师教.我的加入表subjects_teachers,并且有字段id、teacher_id和subject_id.

i have two models. Teacher and Subject joined by HABTM defined both ways. A teacher can teach many subjects and a subject can be taught by many teachers.my join table is subjects_teachers and have fields id,teacher_id and subject_id.

从模型中获取教师数据,我希望所有教师和他们各自的科目,从它的模型中获取学科数据我希望也能看到教授该特定学科的教师

Fetching Teacher data from its model, i expect all teachers and their respective subjects , Fetching Subject data from its model i expect to also see the teachers teaching that particular subject

问题在这两种情况下,关联模型都返回正确数量的记录,但数据不存在.当我显示相应的数组时,我看到 [达到最大深度].

problem on both instances, the associated model returns the correct number of records but the data is absent. i see [maximum depth reached] when i display the respective arrays.

我从连接表删除了 id 字段,并且只修复了教师模型.主题模型仍然存在问题.

I removed the id field from the join table and that fixed only the Teacher model.The Subject model still has the problem.

我只需要知道[达到的最大深度]是什么意思以及为什么从连接表中删除 id 可以解决教师问题,但不能解决主题问题.

i just need to know what [maximum depth reached] means and why removing the id filed from the join table fixed the Teacher problem but not Subject.

另外,如果它很重要,我应该提到我的教师模型主键字段不遵循约定SUBJECT 模型

also if its important i should mention that my Teacher model primary key field doesnt follow convention SUBJECT model

public $hasAndBelongsToMany = array(
    'Teacher' => array(
    'className' => 'Teacher',
    'joinTable' => 'subjects_teachers',
    'foreignKey' => 'subject_id',
    'associationForeignKey' => 'teacher_id',
    'unique' => 'keepExisting'
    )
);

教师模式

public $hasAndBelongsToMany = array(
    'Subject' => array(
    'className' => 'Subject',
    'joinTable' => 'subjects_teachers',
    'foreignKey' => 'teacher_id',
    'associationForeignKey' => 'subject_id',
    'unique' => 'keepExisting'
    )
);

主题结果

array(
(int) 0 => array(
    'Subject' => array(
        'id' => '1',
        'subject_code' => '121',
        'subject_name' => 'Mathematics',
        'compulsory' => true
    ),
    'Teacher' => array(
        (int) 0 => array(
            [maximum depth reached]
        ),
        (int) 1 => array(
            [maximum depth reached]
        ),
        (int) 2 => array(
            [maximum depth reached]
        )
    )
),

删除 id 字段前教师的结果

array(
'Teacher' => array(
    'teacher_id' => '6',
    'first_name' => 'George',
   ),
  'Subject' => array(
    (int) 0 => array(
        'id' => '1',
        'subject_code' => '121',
        'subject_name' => 'Mathematics',
        'compulsory' => true,
        'SubjectsTeacher' => array(
            [maximum depth reached]
        )
    )

去除 id 字段后的结果

'Subject' => array(
    (int) 0 => array(
        'id' => '1',
        'subject_code' => '121',
        'subject_name' => 'Mathematics',
        'compulsory' => true
    ),

推荐答案

您的数据存在,调试器只是不会显示它,因为 depth 选项限制了它.使用 debug()(默认深度 = 25)或 Debugger::dump()/exportVar() 和深度(第二个参数,默认值)到 3) 足够高的深度嵌套数据.

Your data exists, the debugger just wont display it because the depth option limits it. Use debug() (default depth = 25) or Debugger::dump()/exportVar() with a depth (second argument, defaults to 3) high enough for your deeply nested data.

另见

这篇关于cakephp 数组结果 [达到最大深度]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆