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

Issue with User-Defined Variables in Eloquent ORM Queries after Updating to Laravel 11 #86

Closed
Nelwhix opened this issue Jul 1, 2024 · 6 comments · Fixed by #87
Closed
Assignees

Comments

@Nelwhix
Copy link

Nelwhix commented Jul 1, 2024

Hi SingleStore Team,

I have been having a great experience using the SingleStore Laravel driver across several projects. However, after updating to Laravel 11, I started encountering an error when performing find or first queries using the Eloquent ORM. Interestingly, the error does not occur with get queries.

Here is the error message I am receiving:

SQLSTATE[HY000]: General error: 2508 Unknown user-defined variable @`laravel_row` being used before being set. A user defined variable's value can be set via running `select <value> into @<variable name>`. Ensure that this variable is set by running 'select @`laravel_row`'. Also note that user-defined variables are scoped to the session in which they're declared, much like temporary tables. (Connection: singlestore, SQL: select `laravel_table`.*, @laravel_row := if(@laravel_group = `pivot_user_id`, @laravel_row + 1, 1) as `laravel_row`, @laravel_group := `pivot_user_id` from (select @laravel_row := 0, @laravel_group := 0) as `laravel_vars`, (select `workspaces`.*, `user_workspace`.`user_id` as `pivot_user_id`, `user_workspace`.`workspace_id` as `pivot_workspace_id`, `user_workspace`.`created_at` as `pivot_created_at`, `user_workspace`.`updated_at` as `pivot_updated_at` from `workspaces` inner join `user_workspace` on `workspaces`.`id` = `user_workspace`.`workspace_id` where `user_workspace`.`user_id` = 01j00tmy116nw7rqyqp16jt11t and `workspaces`.`id` = 01j00tz9dae8613v4dnz5ctcdg and `workspaces`.`deleted_at` is null order by `pivot_user_id` asc) as `laravel_table` having `laravel_row` <= 1 order by `laravel_row`)

Query:

   $workspace = auth()->user()->workspaces()->find($workspaceId);

This issue occurs on both SingleStore Cloud and the SingleStoreDB Dev Image. I am using the SingleStore Laravel driver version 1.5.4.

Environment Details:

Laravel version: 11.13.0
PHP version: 8.2.19
SingleStore version: 8.5.17 (both cloud and dev image)
I suspect the issue might be related to how user-defined variables are handled in the generated query. Could you please investigate this and provide guidance or a fix?

Thank you for your assistance!

@Nelwhix Nelwhix changed the title Database connection failure when using laravel driver with laravel 11 Database connection failure when using driver with laravel 11 Jul 1, 2024
@Nelwhix Nelwhix changed the title Database connection failure when using driver with laravel 11 Issue with User-Defined Variables in Eloquent ORM Queries after Updating to Laravel 11 Jul 1, 2024
@AdalbertMemSQL AdalbertMemSQL self-assigned this Jul 2, 2024
@JustSteveKing
Copy link

Also watching this 👀

@AdalbertMemSQL
Copy link
Collaborator

Hey
Thanks for reporting the issue.
I'm investigating it at the moment. Looks like Laravel 11 has groupLimit functionality which generates queries unsupported by SingleStore. Will try to fix this

@AdalbertMemSQL
Copy link
Collaborator

This should be fixed by #87
I created a new release (v1.5.5) which contains this fix.

@AdalbertMemSQL AdalbertMemSQL linked a pull request Jul 3, 2024 that will close this issue
@AdalbertMemSQL
Copy link
Collaborator

@Nelwhix @JustSteveKing Can you check and confirm, if it works?

@JustSteveKing
Copy link

@Nelwhix @JustSteveKing Can you check and confirm, if it works?

Will let you know, thanks for the quick turn around!

@bhushan
Copy link

bhushan commented Jul 4, 2024

Thank you @AdalbertMemSQL 🎊

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

Successfully merging a pull request may close this issue.

4 participants