CakePHP 3-嵌套的即时加载错误
我有3个具有多对多关系的表:CakePHP 3-嵌套的即时加载错误,cakephp,orm,eager-loading,Cakephp,Orm,Eager Loading,我有3个具有多对多关系的表: 使用者 团体 工具 我有3个关系透视表: 用户组 工具和用户 组和工具 我正在尝试获取用户->工具,以及用户->组->工具: $user = TableRegistry::get('Users') ->find() ->where(['id' => 1]) ->contain(['Tools'
- 使用者
- 团体
- 工具
- 用户组
- 工具和用户
- 组和工具
$user = TableRegistry::get('Users')
->find()
->where(['id' => 1])
->contain(['Tools'])
->contain(['Groups.Tools'])
->first();
但我得到一个错误:“组与工具不关联”
我遵循所有约定,创建了类:
- GroupsTable,在初始化器方法处具有以下关系
$this->belongsToMany('Tools'); $this->belongsToMany('Users');
$this->belongsToMany('Users'); $this->belongsToMany('Groups');
$this->belongsToMany('Tools'); $this->belongsToMany('Groups');
$this->belongsToMany('YourPluginName.Tools'); $this->belongsToMany('YourPluginName.Users');
$this->belongsToMany('YourPluginName.Users'); $this->belongsToMany('YourPluginName.Groups');
$this->belongsToMany('YourPluginName.Tools'); $this->belongsToMany('YourPluginName.Groups');
- ToolsTable,在初始化器方法处具有以下关系
$this->belongsToMany('Tools'); $this->belongsToMany('Users');
$this->belongsToMany('Users'); $this->belongsToMany('Groups');
$this->belongsToMany('Tools'); $this->belongsToMany('Groups');
$this->belongsToMany('YourPluginName.Tools'); $this->belongsToMany('YourPluginName.Users');
$this->belongsToMany('YourPluginName.Users'); $this->belongsToMany('YourPluginName.Groups');
$this->belongsToMany('YourPluginName.Tools'); $this->belongsToMany('YourPluginName.Groups');
- UsersTable,在初始化器方法处具有以下关系
$this->belongsToMany('Tools'); $this->belongsToMany('Users');
$this->belongsToMany('Users'); $this->belongsToMany('Groups');
$this->belongsToMany('Tools'); $this->belongsToMany('Groups');
$this->belongsToMany('YourPluginName.Tools'); $this->belongsToMany('YourPluginName.Users');
$this->belongsToMany('YourPluginName.Users'); $this->belongsToMany('YourPluginName.Groups');
$this->belongsToMany('YourPluginName.Tools'); $this->belongsToMany('YourPluginName.Groups');
$this->belongsToMany('Tools');
$this->belongsToMany('Users');
$this->belongsToMany('Users');
$this->belongsToMany('Groups');
$this->belongsToMany('Tools');
$this->belongsToMany('Groups');
$this->belongsToMany('YourPluginName.Tools');
$this->belongsToMany('YourPluginName.Users');
$this->belongsToMany('YourPluginName.Users');
$this->belongsToMany('YourPluginName.Groups');
$this->belongsToMany('YourPluginName.Tools');
$this->belongsToMany('YourPluginName.Groups');
ToolsTable,在初始化器方法处具有以下关系
$this->belongsToMany('Tools');
$this->belongsToMany('Users');
$this->belongsToMany('Users');
$this->belongsToMany('Groups');
$this->belongsToMany('Tools');
$this->belongsToMany('Groups');
$this->belongsToMany('YourPluginName.Tools');
$this->belongsToMany('YourPluginName.Users');
$this->belongsToMany('YourPluginName.Users');
$this->belongsToMany('YourPluginName.Groups');
$this->belongsToMany('YourPluginName.Tools');
$this->belongsToMany('YourPluginName.Groups');
UsersTable,在初始化器方法处具有以下关系
$this->belongsToMany('Tools');
$this->belongsToMany('Users');
$this->belongsToMany('Users');
$this->belongsToMany('Groups');
$this->belongsToMany('Tools');
$this->belongsToMany('Groups');
$this->belongsToMany('YourPluginName.Tools');
$this->belongsToMany('YourPluginName.Users');
$this->belongsToMany('YourPluginName.Users');
$this->belongsToMany('YourPluginName.Groups');
$this->belongsToMany('YourPluginName.Tools');
$this->belongsToMany('YourPluginName.Groups');