-
Notifications
You must be signed in to change notification settings - Fork 1.4k
PHPORM-320 Fix aliasing .id field path to ._id #3353
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,20 +34,24 @@ jobs: | |
- "11.*" | ||
- "12.*" | ||
driver: | ||
- 1 | ||
- 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have to change the default driver version that is tested to match the ruleset from #3347 |
||
include: | ||
- php: "8.1" | ||
laravel: "10.*" | ||
mongodb: "5.0" | ||
mode: "low-deps" | ||
os: "ubuntu-latest" | ||
driver: 1.x | ||
driver_version: "1.21.0" | ||
driver: 1 | ||
- php: "8.3" | ||
laravel: "11.*" | ||
mongodb: "8.0" | ||
os: "ubuntu-latest" | ||
driver: 1 | ||
- php: "8.4" | ||
laravel: "12.*" | ||
mongodb: "8.0" | ||
os: "ubuntu-latest" | ||
driver: 2 | ||
driver: 1 | ||
exclude: | ||
- php: "8.1" | ||
laravel: "11.*" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1599,29 +1599,86 @@ public static function getEloquentMethodsNotSupported() | |
yield 'orWhereIntegerNotInRaw' => [fn (Builder $builder) => $builder->orWhereIntegerNotInRaw('id', ['1a', 2])]; | ||
} | ||
|
||
public function testRenameEmbeddedIdFieldCanBeDisabled() | ||
#[DataProvider('provideDisableRenameEmbeddedIdField')] | ||
public function testDisableRenameEmbeddedIdField(array $expected, Closure $build) | ||
{ | ||
$builder = $this->getBuilder(false); | ||
$this->assertFalse($builder->getConnection()->getRenameEmbeddedIdField()); | ||
|
||
$mql = $builder | ||
->where('id', '=', 10) | ||
->where('nested.id', '=', 20) | ||
->where('embed', '=', ['id' => 30]) | ||
->toMql(); | ||
|
||
$this->assertEquals([ | ||
'find' => [ | ||
[ | ||
'$and' => [ | ||
['_id' => 10], | ||
['nested.id' => 20], | ||
['embed' => ['id' => 30]], | ||
$mql = $build($builder)->toMql(); | ||
|
||
$this->assertEquals($expected, $mql); | ||
} | ||
|
||
public static function provideDisableRenameEmbeddedIdField() | ||
{ | ||
yield 'rename embedded id field' => [ | ||
[ | ||
'find' => [ | ||
[ | ||
'$and' => [ | ||
['_id' => 10], | ||
['nested.id' => 20], | ||
['embed' => ['id' => 30]], | ||
], | ||
], | ||
['typeMap' => ['root' => 'object', 'document' => 'array']], | ||
], | ||
], | ||
fn (Builder $builder) => $builder->where('id', '=', 10) | ||
->where('nested.id', '=', 20) | ||
->where('embed', '=', ['id' => 30]), | ||
]; | ||
|
||
yield 'rename root id' => [ | ||
['find' => [['_id' => 10], ['typeMap' => ['root' => 'object', 'document' => 'array']]]], | ||
fn (Builder $builder) => $builder->where('id', '=', 10), | ||
]; | ||
|
||
yield 'nested id not renamed' => [ | ||
['find' => [['nested.id' => 20], ['typeMap' => ['root' => 'object', 'document' => 'array']]]], | ||
fn (Builder $builder) => $builder->where('nested.id', '=', 20), | ||
]; | ||
|
||
yield 'embed id not renamed' => [ | ||
['find' => [['embed' => ['id' => 30]], ['typeMap' => ['root' => 'object', 'document' => 'array']]]], | ||
fn (Builder $builder) => $builder->where('embed', '=', ['id' => 30]), | ||
]; | ||
|
||
yield 'nested $and in $or' => [ | ||
[ | ||
'find' => [ | ||
[ | ||
'$or' => [ | ||
[ | ||
'$and' => [ | ||
['_id' => 10], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are flaws in the conversion if you use advanced queries. This transformation from laravel-mongodb/src/Query/Builder.php Lines 1209 to 1212 in bdae18d
// Compatibility with Eloquent queries that uses "id" instead of MongoDB's _id
if ($where['column'] === 'id') {
$where['column'] = '_id';
}
|
||
['nested.id' => 20], | ||
['embed' => ['id' => 30]], | ||
], | ||
], | ||
[ | ||
'$and' => [ | ||
['_id' => 40], | ||
['nested.id' => 50], | ||
['embed' => ['id' => 60]], | ||
], | ||
], | ||
], | ||
], | ||
['typeMap' => ['root' => 'object', 'document' => 'array']], | ||
], | ||
['typeMap' => ['root' => 'object', 'document' => 'array']], | ||
], | ||
], $mql); | ||
fn (Builder $builder) => $builder->orWhere(function (Builder $builder) { | ||
return $builder->where('id', '=', 10) | ||
->where('nested.id', '=', 20) | ||
->where('embed', '=', ['id' => 30]); | ||
})->orWhere(function (Builder $builder) { | ||
return $builder->where('id', '=', 40) | ||
->where('nested.id', '=', 50) | ||
->where('embed', '=', ['id' => 60]); | ||
}), | ||
]; | ||
} | ||
|
||
private function getBuilder(bool $renameEmbeddedIdField = true): Builder | ||
|