Mysql cakephp3中的递归?

Mysql cakephp3中的递归?,mysql,cakephp,orm,associations,Mysql,Cakephp,Orm,Associations,这是我的表格关联代码: class UserMastersTable extends Table { public function initialize(array $config) { parent::initialize($config); $this->table('user_masters'); $this->hasOne('person_masters', [ 'className'

这是我的表格关联代码:

class UserMastersTable extends Table {
  public function initialize(array $config) {
        parent::initialize($config); 
        $this->table('user_masters');     
        $this->hasOne('person_masters', [
            'className' => 'person_masters',
            'foreign_key'=>'user_master_id',
            'dependent' => true
        ]);
    }
}
在控制器中使用时: $this->UserMasters->get($id); 它只会导致用户掌握表格数据。。 那么,我怎样才能获得相关的表数据呢???

使用contain() 从手册中复制粘贴:

要加载主模型时,应使用contain(),并且 它的相关数据。而contain()将允许您应用其他 对于已加载关联的条件,不能约束 基于关联的主模型。有关 contain(),查看急切加载关联


在投入试错驱动开发之前如果在这之前您已经完成了手册中的一个教程,那么这一点就很清楚了。所以现在就做吧,它们将涵盖更多的基础知识。

对于检索关联数据,每次在查询中使用“包含”?是否有任何方法可以在不使用每次“包含”的情况下检索关联数据默认值??我们可以在模型中全局定义它吗?“递归”被删除,因为始终包含ASSOC是一种不好的做法。只有在真正需要的时候才应该包括它们。但是,您可以将疯狂添加回beforeFind()回调中,请参见->您介意将答案标记为正确吗?谢谢
// In a controller or table method.

// As an option to find()
$query = $articles->find('all', ['contain' => ['Authors', 'Comments']]);

// As a method on the query object
$query = $articles->find('all');
$query->contain(['Authors', 'Comments']);