Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PHPORM-239 Convert _id and UTCDateTime in results of Model::raw() before hydratation #3152

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

Merged
GromNaN merged 5 commits into mongodb:5.x from GromNaN:PHPORM-239
Sep 17, 2024

Conversation

@GromNaN
Copy link
Member

@GromNaN GromNaN commented Sep 13, 2024
edited
Loading

Fix PHPORM-239
Fix #3151

Checklist

  • Add tests and ensure they pass
  • Add an entry to the CHANGELOG.md file

Copy link
Member Author

GromNaN commented Sep 13, 2024

I don't see any way to change this behavior without breaking backward compatibility.

@GromNaN GromNaN marked this pull request as ready for review September 17, 2024 10:42
@GromNaN GromNaN requested a review from a team as a code owner September 17, 2024 10:42
@GromNaN GromNaN force-pushed the PHPORM-239 branch 2 times, most recently from 10c98ee to 7f0b77e Compare September 17, 2024 10:44

return $this->model->newFromBuilder((array) $results);
// Convert MongoDB Document to a single object.
if (is_object($results) && (property_exists($results, '_id') || property_exists($results, 'id'))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed that PHP correctly calls the has_property handler when using property_exists: https://github.com/php/php-src/blob/1be989bbf0e46db8438384db184fca424392cfef/Zend/zend_builtin_functions.c#L1020..L1023

GromNaN and jensk reacted with thumbs up emoji
@GromNaN GromNaN changed the title (削除) PHPORM-239 Apply result transformation to raw() queries (削除ここまで) (追記) PHPORM-239 Convert _id and UTCDateTime in results of Model::raw() before hydratation (追記ここまで) Sep 17, 2024
Copy link
Member

alcaeus commented Sep 17, 2024

LGTM, but tests need a little more work.

Comment on lines +946 to +947
$this->assertEquals(['foo' => 'bar'], (array) $user->embed);
$this->assertEquals([1, 2, 3], (array) $user->list);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't convert nested documents and array into array for single result. This is easily done for cursor and BSON documents with typemap.

Comment on lines +1385 to +1403
yield 'raw filter with _id and date' => [
[
'find' => [
[
'$and' => [
[
'$or' => [
['foo._id' => 1],
['created_at' => ['$gte' => new UTCDateTime(new DateTimeImmutable('2018年09月30日 00:00:00.000 +00:00'))]],
],
],
['age' => 15],
],
],
[], // options
],
],
fn (Builder $builder) => $builder->where([
'$or' => [
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this test case to ensure DB::where($filter)->get() is identical to $collection->find($filter) (for the doc team).

@GromNaN GromNaN merged commit 38dc1e3 into mongodb:5.x Sep 17, 2024
27 checks passed
@GromNaN GromNaN deleted the PHPORM-239 branch December 30, 2024 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@alcaeus alcaeus alcaeus approved these changes

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

_id returned by raw()

2 participants

AltStyle によって変換されたページ (->オリジナル) /