Belongsto AND belongsToMany

Hi

I have a model where an entity belongsto and belongsToMany users:

    $this->belongsTo('Users', [
        'foreignKey' => 'user_id',
        'joinType' => 'INNER',
         'propertyName' => 'utilisateur'
    ]);
   $this->belongsToMany('Users', [
        'foreignKey' => 'quete_id',
        'targetForeignKey' => 'user_id',
        'joinTable' => 'users_quetes',
         'propertyName' => 'utilisateurs'
    ]);

I want to eager load the user and the users in pagination , so I do this :
$this->paginate[‘contain’] = [‘Users’];

but only the belongsToMany association is loaded. If I comment the belongsToMany association, I Got an entity in utilisateur var;

I have try $this->paginate[‘contain’] = [‘Users’,‘User’];
but it says that the association ‘User’ is not defined;

I have try $this->paginate[‘contain’] = [‘Users’,‘utilisateur’];
but it says that the association ‘utilisateur’ is not defined;
I guess the problems is because it is link to the same table

My question is how to eager load the both associations (users and user) in pagination

You cannot have 2 associations with the same alias. Rename one of them to something else, for e.g.:

   $this->belongsToMany('RelatedUsers', [
       'className' => 'Users',
        'foreignKey' => 'quete_id',
        'targetForeignKey' => 'user_id',
        'joinTable' => 'users_quetes',
         'propertyName' => 'utilisateurs'
    ]);

Then you can use $this->paginate[‘contain’] = [‘Users’, 'RelatedUsers'];.