Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation on hasMany association #25

Open
thejoelinux opened this issue Oct 31, 2019 · 2 comments
Open

Documentation on hasMany association #25

thejoelinux opened this issue Oct 31, 2019 · 2 comments

Comments

@thejoelinux
Copy link
Contributor

Following closed issue #16, documentation on the subject is needed. I set up a small sample project on https://github.com/thejoelinux/cakephp-dt-test to have a test case.

I want to have a list of customers in datatables, with the number of invoices for each, or the sum of invoices if possible.

I try to find a way to do so, but in the meanwhile, any help would be very much appreciated.

@joakim-emagine
Copy link

joakim-emagine commented Oct 31, 2019

@thejoelinux you will need to do something along the lines

in Template.../datatables/configName.ctp

$results->select([
 'invoice_count' => $results->newExpr()->add('sql expression that counts');
 'invoice_count' => $results->func()->count('Invoices.id')
]);
$results->group('Customers.id');

Can use either method, I think.

@thejoelinux
Copy link
Contributor Author

Thanks for the tip. I used this in my sample project, issue 2, and I will soon commit a solution. It was pretty easy ... once done :)

Next, I'll propose a documentation patch here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants