Issue
When I query without select()
I get contain()
[owner] array, but using select() with params it doesn't contain [owner]
array. Is there any problem using select and contain at same time ?
$payments = $this->Payments->find()
->select($this->Payments)
->select(['tot_amount'=>'sum(Payments.amount)'])
->select(['tot_owner_amt'=>'sum(Payments.owner_amt)'])
->select(['tot_admin_amt'=>'sum(Payments.admin_amt)'])
->contain(['Owners'])
->group(['Payments.owner_id'])
->all();
debug($payments); die();
Debug array
\src\Controller\PaymentsController.php (line 72)
object(Cake\ORM\ResultSet) {
'items' => [
(int) 0 => object(App\Model\Entity\Payment) {
'id' => (int) 4,
'user_id' => (int) 4,
'owner_id' => (int) 5,
'wifi_id' => (int) 2,
'payment_unique_key' => 'pay-9999',
'payment_type' => 'paypal',
'amount' => (float) 10,
'owner_amt' => (float) 1,
'admin_amt' => (float) 9,
'ispaid' => false,
'paid_at' => object(Cake\I18n\FrozenTime) {
'time' => '2017-01-10T11:21:00+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'is_refund' => false,
'isactive' => true,
'isdel' => null,
'created' => object(Cake\I18n\FrozenTime) {
'time' => '2017-01-10T11:22:24+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\FrozenTime) {
'time' => '2017-01-10T11:30:26+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'tot_amount' => '10.00',
'tot_owner_amt' => '1.00',
'tot_admin_amt' => '9.00',
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Payments'
},
(int) 1 => object(App\Model\Entity\Payment) {
'id' => (int) 1,
'user_id' => (int) 1,
'owner_id' => (int) 6,
'wifi_id' => (int) 1,
'payment_unique_key' => 'adfasdf',
'payment_type' => 'paypal',
'amount' => (float) 500,
'owner_amt' => (float) 50,
'admin_amt' => (float) 449,
'ispaid' => false,
'paid_at' => object(Cake\I18n\FrozenTime) {
'time' => '2017-01-10T11:21:00+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'is_refund' => false,
'isactive' => true,
'isdel' => null,
'created' => object(Cake\I18n\FrozenTime) {
'time' => '2017-01-10T11:22:24+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\FrozenTime) {
'time' => '2017-01-10T11:30:26+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'tot_amount' => '2000.00',
'tot_owner_amt' => '200.00',
'tot_admin_amt' => '1798.00',
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Payments'
}
]
}
Did i miss anything in above code? Thanks in advance
Solution
Need to select the owners array in select
like select($this->Payments->Owners)
, Thanks @burzum
Solutions
$payments = $this->Payments->find()
->select($this->Payments)
->select(['tot_amount'=>'sum(Payments.amount)'])
->select(['tot_owner_amt'=>'sum(Payments.owner_amt)'])
->select(['tot_admin_amt'=>'sum(Payments.admin_amt)'])
->select($this->Payments->Owners)
->contain(['Owners'])
->group(['Payments.owner_id'])
->all();
Answered By - tarikul05
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.