I have done model association in cake 3.2
Here i have done it for one id of same table .
I have tried to do it for other one ,but its not working at all
below is the flow.
This output i am getting
{
"id": 1,
"publisher_id": 133,
"user_id": 118,
"Publisher": {
"id": 133,
"name": "Sradha sradha"
}
Here i want to bind the user id also ,which is belongs to that same user table
The output should come like this(I want to get like this below)
{
"id": 1,
"publisher_id": 133,
"user_id": 118,
"Publisher": {
"id": 133,
"name": "Sradha sradha"
}
"Users": {
"id": 118,
"name": "Sradha anjo"
}
Here both publisher_id and user_id are belongs to same user table .
$this->AdminRevenues->belongsTo('Users', [
'className' => 'Users',
'foreignKey' => 'user_id',
'propertyName' => 'Users']);
$this->AdminRevenues->belongsTo('Users', [
'className' => 'Publisher',
'foreignKey' => 'publisher_id',
'propertyName' => 'Publisher']);
$totalAdminRevenue = $this->AdminRevenues->find('all')
->contain([
'Users' => ['queryBuilder' => function ($q) {
return $q->select(['id', 'name']);
}]])
->toArray();
Please suggest ,any suggestion will be highly appreciated.
belongsTo('Publisher', [ 'className' => 'Users',
. Same in the query. – Romola