-
-
Notifications
You must be signed in to change notification settings - Fork 509
Preserve \MongoRegex on string typed identifier #1298
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
Preserve \MongoRegex on string typed identifier #1298
Conversation
@@ -30,7 +30,7 @@ class StringType extends Type | |||
{ | |||
public function convertToDatabaseValue($value) | |||
{ | |||
return $value !== null ? (string) $value : null; | |||
return $value !== null ? $value instanceof \MongoRegex ? $value : (string) $value : null; |
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.
Can we put this new check in normal if
? As much as I love ternary operator it'll more readable :)
@malarzm agreed, it looked nasty.. i changed it a bit, looks way more simple now ;-) |
@@ -30,7 +30,7 @@ class StringType extends Type | |||
{ | |||
public function convertToDatabaseValue($value) | |||
{ | |||
return $value !== null ? (string) $value : null; | |||
return (is_null($value) || $value instanceof \MongoRegex) ? $value : (string) $value; |
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.
Nitpicking a bit maybe, but could we use $value === null
? I don't think we use function checks anywhere
I've left one more comment and could you also please squash the commits? |
1feb32b
to
a95f594
Compare
@malarzm ok, changed and squashed ;-) |
Manually merged in 17be5e2. Thanks! |
This is a possible fix for #1294 and a unit test to avoid regression.
I'm not sure if this should be handled in the
Type
class. It makes kinda sense as it's the culprit. But maybe it's a too much narrow check (topic wise) in theType
. But I'm not sure where it could be handled elsewhere asconvertToDatabaseValue()
will be called anyway and the\MongoRegex
instance would be lost(?)