Table Alias not getting right for softDelete on Model #41708
Unanswered
parmonov98
asked this question in
Q&A
Replies: 4 comments 2 replies
-
Can you also share employee_transactions table columns? Did you add softDeletes() to your migration like:
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Still an issue in 2024... |
Beta Was this translation helpful? Give feedback.
1 reply
-
Raw queries should be avoided when possible. Please try this:
|
Beta Was this translation helpful? Give feedback.
0 replies
-
I wrote a solution fot this. here you are the PR, is a rudimentary way to resolve this problem. Let's see what happen. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description:
I enabled softDelete in Model using trait. and the tale has deleted_at column.
This query
EmployeeTransaction::query()->from("employee_transactions as et")
->leftJoin('employees as e', 'e.id', '=', 'et.employee_id')
->whereRaw("DATE_FORMAT(et.date, '%Y-%m-%d') >= '$this->from_date'")
->whereRaw("DATE_FORMAT(et.date, '%Y-%m-%d') <= '$this->to_date'")
->groupBy(DB::raw('et.employee_id'))
->select(
DB::raw("
e
.id
as employee_id"),DB::raw("(SELECT SUM(
et
.earning_amount
) - SUM(et
.payment_amount
) from employee_transactions as et where et.employee_id = e.id GROUP BY et.employee_id) as left_amount"),DB::raw("CONCAT(
e
.first_name
, '',e
.last_name
) as name"),DB::raw("SUM(
et
.earning_amount
) as earning_amount"),DB::raw("SUM(
et
.payment_amount
) as payment_amount"),DB::raw("SUM(earning_amount - payment_amount) as difference_amount"),
DB::raw("
et
.date
as date"))
It throws an error:

Steps To Reproduce:
create a eloquent query using model and change table name using from or fromRaw
Beta Was this translation helpful? Give feedback.
All reactions