-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
PHPORM-239 Convert _id
and UTCDateTime
in results of Model::raw()
before hydratation
#3152
Conversation
I don't see any way to change this behavior without breaking backward compatibility. |
10c98ee
to
7f0b77e
Compare
|
||
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'))) { |
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.
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
_id
and UTCDateTime
in results of Model::raw()
before hydratation
LGTM, but tests need a little more work. |
$this->assertEquals(['foo' => 'bar'], (array) $user->embed); | ||
$this->assertEquals([1, 2, 3], (array) $user->list); |
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.
We don't convert nested documents and array into array for single result. This is easily done for cursor and BSON documents with typemap.
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' => [ |
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.
Added this test case to ensure DB::where($filter)->get()
is identical to $collection->find($filter)
(for the doc team).
Fix PHPORM-239
Fix #3151
Checklist