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.
I believe that IS NOT is only for use with NULL, you should be using 'outstanding >' => 0.
Your contained records are not showing up, because you have used select to tell it the fields you want. I personally never bother with this, I think that any performance benefit gained by limiting the fields pulled over from the database is going to be minimal, compared to the time I’ll waste when some calculation or display somewhere changes to include a field that is included in most queries but not all of them and I have to track down what’s going wrong.
But if you insist on using it (there are, after all, times when it’s required), then you can add ->enableAutoFields(true) to your query, and that will pull in the associated records in their entirety, or I think you can use queryBuilder arguments in your containment if you want to further limit what fields are selected from those records.
Thanks for the hint with the ->enableAutoFields(true) - this really did the trick. I also removed the select statement from the query. Honestly, there was no real intention to limit the columns, I was just trying to find out how to create a proper query at all and followed the documentation.
Another obstacle was, that the associated objects are spelled lowercase in the View - which took me some time to find out.
But now the View works as intended!
Thanks a lot,
Marcus.
If you don’t have a select clause any more, you don’t need enableAutoFields. And yes, associated objects are always spelled with lowercase. You can use debug($whatver) to look at objects whenever you run into situations where you’re not sure exactly what structure the data has.