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

Preserve \MongoRegex on string typed identifier #1298

Conversation

narcoticfresh
Copy link
Contributor

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 the Type. But I'm not sure where it could be handled elsewhere as convertToDatabaseValue() will be called anyway and the \MongoRegex instance would be lost(?)

@@ -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;
Copy link
Member

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 :)

@narcoticfresh
Copy link
Contributor Author

@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;
Copy link
Member

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

@malarzm
Copy link
Member

malarzm commented Dec 12, 2015

I've left one more comment and could you also please squash the commits?

@alcaeus alcaeus added the Bug label Dec 12, 2015
@alcaeus alcaeus added this to the 1.1 milestone Dec 12, 2015
@narcoticfresh
Copy link
Contributor Author

@malarzm ok, changed and squashed ;-)

@alcaeus alcaeus modified the milestones: 1.0.4, 1.1 Dec 14, 2015
@alcaeus
Copy link
Member

alcaeus commented Dec 14, 2015

Manually merged in 17be5e2. Thanks!

@alcaeus alcaeus closed this Dec 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants