-
Notifications
You must be signed in to change notification settings - Fork 1.5k
make sure $column is string #2593
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
Conversation
Hello @wivaku, thanks for your contribution. Would you like to add a test for this feature to avoid regression. |
Hi @GromNaN , you're welcome. Do you feel a test is needed for casting to a string? The casting is similar to other places in the code, e.g. laravel-mongodb/src/Query/Builder.php Line 530 in ad79fb1
|
This is a feature and we need to be sure this feature keeps working when we work on the codebase. It's not about testing |
I don't mind adding a test, but it seems I am not exactly sure what + how. I tried running the tests using
This is the test that could be added to
|
Native Eloquent allows $column to be stringable(). Not possible when using as array key.
Thank you @wivaku, I added more tests and refactored the change so every operations have a stringified |
@@ -1004,8 +1004,14 @@ protected function compileWheres(): array | |||
$where['boolean'] = 'or'.(str_ends_with($where['boolean'], 'not') ? ' not' : ''); | |||
} | |||
|
|||
// Column name can be a Stringable object. | |||
if (isset($where['column']) && $where['column'] instanceof \Stringable) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the check for Stringable
here but not in other places? Is there a reason why we can't always cast to string
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed a if
statement to check if column
is set, so I added the instanceof
to avoid reassigning if the value is already a string. In other places, we know $column
is set and we are not assigning the casted value.
Thank you @wivaku |
Native Eloquent allows $column to be stringable(). Not possible when using as array key.
Is issue when using e.g. Filament column search.