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

Using a nested select in a CASE statement causing issues #10

Open
kingthrillgore opened this issue Jul 2, 2024 · 0 comments
Open

Using a nested select in a CASE statement causing issues #10

kingthrillgore opened this issue Jul 2, 2024 · 0 comments

Comments

@kingthrillgore
Copy link

kingthrillgore commented Jul 2, 2024

I have a one-off case where some additional CASE output has to be added to the SELECT, and the criteria for at least one of them relies on a nested select that operates off a count of adjacent records.

The problem at hand is, when defined in the below code, the SQL is malformed and won't work. I'm certain I can make it work solely as Raw, but that kind of defeats the purpose of using this plugin.

The actual SELECT I wish to add is as follows:

$pendingShifts = $client->shifts()->with('caregiver', 'activities')
            ->doesntHave('invoices')
            ->whereNotNull('checked_out_time')
            ->case(function (CaseBuilder $case) {
                $case->when('checked_out_time', '>=', 'INTERVAL 25 HOUR')->then('Requires Attention')
                ->whenRaw('(select count(*) from shift_activities where shift_id = shifts.id) <= 0')->thenRaw('Requires Attention')
                ->else('Complete');
            }, 'VisitStatus')
            ->get();

But the generated SQL appears to be malformed, lacking quotes around the thenRaw statements.

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

1 participant