I have a simple table with earnings and outstanding payments and the customer_id of the client who owes that payment.
For managing the outstanding payments, I want a View that lists all outstanding payments and the fullname of the customer.
In the controller I created a query that selects the earnings records with outstanding payments:
$query = $this->Earnings->find();
$query->select([‘id’, ‘date’, ‘customer_id’, ‘service’, ‘outstanding’, ‘payment_id’]);
$query->where([‘outstanding IS NOT’ => 0]);
BTW: I was wondering if there is any better way to filter the records just by finding all where outstanding > 0?
Anyway, I then store the result in a variable which I pass to the View:
$outstandings = $this->paginate($query, [‘contain’ => [‘Customers’, ‘Payments’]]);
Although I included ‘Customers’ in ‘contain’, I don’t get any associated customer records. The resultset just holds the customer_id, but no further Customer object. I am therefore not able to access the Customer fields like its fullname.
what’s wrong? or what would be the proper way?