-
Notifications
You must be signed in to change notification settings - Fork 12
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
Not bringing back hasMany Association #16
Comments
A workaround for anyone trying this, I had to use: $results->select(['total_paid' => $results->func()->sum('TransactionPayments.amount')])
->leftJoinWith('TransactionPayments')
->group(['TransactionPayments.id']); in the datatables/configname.ctp In my case i did an aggregate function sum(). |
Try this... By default, the plugin get only the fields that is need. You must declare all on '->column()' or '->databaseColumn()' methods. If you're using it this way you'll get all associations. The second method is for get only database information, but not create a datatable column. Even using 'contain', you will need to tell which database cols you want to use if there is no column in the 'datatables' that uses it. Quick example:
|
This works! thanks much. |
Hello, sorry to bring it back, but i really don't get it. Let's say you have a Customers list, and you want a column with the number of Invoices for the customer or, maybe, the sum of all the invoices (considering the amount of the invoice is in the Invoices table, not in some related table). We have an hasMany association between Customers and Invoices. DataTables configuration is something like: $this->DataTables->createConfig('Customers')
->column('Customers.name', ['label' => 'Name'])
->queryOptions(['contain' => 'Invoices']) Past this, I'm not able to determine what is necessary to display, count, and/or sum this row. I think it really misses some explicit documentation on the subject. I would like to write it. I'll try to set up a small example project to show what I'm trying to do. |
The plugin works great when for belongsto associations but does not work correctly for hasMany associations.
Getting either a column not found or
field
must be included in list.Column not found: 1054 Unknown column 'TransactionPayments.transaction_id' in 'field list'
As you can see below the 'TransactionPayments' table is not included in the sql statement.
I have left out some columns because of length.
SQL statement
The text was updated successfully, but these errors were encountered: