Hello I have 5 tables.
Instances (Model in question)
InstancesUserGroups (Join Table)
UserGroups
UsersUserGroups (Join Table)
Users (Table which I need to load into Model in question)
Associations
Users–<UsersUserGroups>–UserGroups–<InstancesUserGroups>–Instances
Issue: trying to load Users from Instances Model
My BelongsToMany for UserGroups works just fine:
$this->belongsToMany(‘UserGroups’, [
‘foreignKey’ => ‘instance_id’, //instances - primary id
‘targetForeignKey’ => ‘ug_id’, //user_groups - primary id
‘joinTable’ => ‘insatnces_user_groups’,
‘through’ => ‘InsatncesUserGroups’
]);
But not sure how to create BelongsToMany for Users, here is what i currently have:
$this->belongsToMany('Users', [ 'foreignKey' => 'ug_id', //instances - primary id 'targetForeignKey' => 'user_id', //users - primary id 'joinTable' => 'users_user_groups', 'through' => 'UsersUserGroups' ]);
Which wouldn’t work since its conditions is WHERE ug_id = instance_id in question
I’m aware that, I can load the users from the controller with
‘contain’ => [‘UserGroups’ => [‘Users’]]
but I want to load Users as a separate array to loop over separately.
Simply wondering if cakephp3 has such functionality? Maybe a through => through???