I have the following table structure:
- Users
- Tools
- Groups
All of them have many to many associations
And I already have the pivot tables:
- groups_tools
- groups_users
- tools_users
I'm trying to do the following query:
TableRegistry::get('Users')
->find()
->where(['id' => 1])
->contain(['Groups.Tools'])
->first();
I'm getting the following error
Groups are not associated with Tools
However, I think I'm following all the conventions.
class GroupsTable extends Table
{
public function initialize(array $config)
{
$this->addBehavior('Timestamp');
$this->belongsToMany('Tools');
$this->belongsToMany('Users');
}
}
class ToolsTable extends Table
{
public function initialize(array $config)
{
$this->addBehavior('Timestamp');
$this->belongsToMany('Users');
$this->belongsToMany('Groups');
}
}
class UsersTable extends Table
{
public function initialize(array $config)
{
$this->addBehavior('Timestamp');
$this->belongsToMany('Tools');
$this->belongsToMany('Groups');
}
}