orderLogic code no longer working #621
-
Hi, here's some custom column ordering logic that worked fine with Backpack 5 but now no longer works after the upgrade to version 6. 'orderLogic' => function ($query, $column, $columnDirection) {
return $query->leftJoin('sales_invoices', 'customers.id', '=', 'sales_invoices.customer_id')
->select('customers.*', DB::raw('SUM(sales_invoices.euro_total_price_excl_tax) as sum_sales'))
->groupBy('customers.id')
->orderBy('sum_sales', $columnDirection);
} This now throws this error: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'id'SELECT
count(*) AS total_rows
FROM
(
SELECT
*,
SUM(sales_invoices.euro_total_price_excl_tax) AS sum_sales
FROM
`customers`
LEFT JOIN `sales_invoices` ON `customers`.`id` = `sales_invoices`.`customer_id`
GROUP BY
`customers`.`id`
) AS `customers_aggregator` Any clues on where I need to look to address this? The error just doesn't make sense to me. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
I am not sure how it worked on previous version, we didn't change nothing there from v5 to v6. That's my guess, can you try it ? Cheers |
Beta Was this translation helpful? Give feedback.
-
The sub-query is fine when executed against the database. The outer query for |
Beta Was this translation helpful? Give feedback.
-
I think the problem is that after the |
Beta Was this translation helpful? Give feedback.
-
@o15a3d4l11s2 Thanks, yes I was thinking of that as well but somehow the query is always picking up I have now figured out a much easier, full Eloquent query, approach: return $query->withSum('sales_invoices', 'euro_total_price_excl_tax')
->orderBy('sales_invoices_sum_euro_total_price_excl_tax', $columnDirection); Works like a charm. |
Beta Was this translation helpful? Give feedback.
@o15a3d4l11s2 Thanks, yes I was thinking of that as well but somehow the query is always picking up
*
in the SELECT.I have now figured out a much easier, full Eloquent query, approach:
Works like a charm.