Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
laravel-mongodb
Commits
4d81b402
Commit
4d81b402
authored
Feb 08, 2020
by
Stas
Committed by
GitHub
Feb 08, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1885 from mauri870/drop-compound-index
Fix dropIndex for compound indexes with sorting order
parents
c6313cb2
9b062ac0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
2 deletions
+26
-2
Blueprint.php
src/Jenssegers/Mongodb/Schema/Blueprint.php
+12
-2
SchemaTest.php
tests/SchemaTest.php
+14
-0
No files found.
src/Jenssegers/Mongodb/Schema/Blueprint.php
View file @
4d81b402
...
...
@@ -129,8 +129,18 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
// Transform the columns to the index name.
$transform
=
[];
foreach
(
$indexOrColumns
as
$column
)
{
$transform
[
$column
]
=
$column
.
'_1'
;
foreach
(
$indexOrColumns
as
$key
=>
$value
)
{
if
(
is_int
(
$key
))
{
// There is no sorting order, use the default.
$column
=
$value
;
$sorting
=
'1'
;
}
else
{
// This is a column with sorting order e.g 'my_column' => -1.
$column
=
$key
;
$sorting
=
$value
;
}
$transform
[
$column
]
=
$column
.
"_"
.
$sorting
;
}
$indexOrColumns
=
implode
(
'_'
,
$transform
);
...
...
tests/SchemaTest.php
View file @
4d81b402
...
...
@@ -132,6 +132,20 @@ class SchemaTest extends TestCase
$index
=
$this
->
getIndex
(
'newcollection'
,
'field_a_1_field_b_1'
);
$this
->
assertFalse
(
$index
);
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
index
([
'field_a'
=>
-
1
,
'field_b'
=>
1
]);
});
$index
=
$this
->
getIndex
(
'newcollection'
,
'field_a_-1_field_b_1'
);
$this
->
assertNotNull
(
$index
);
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
dropIndex
([
'field_a'
=>
-
1
,
'field_b'
=>
1
]);
});
$index
=
$this
->
getIndex
(
'newcollection'
,
'field_a_-1_field_b_1'
);
$this
->
assertFalse
(
$index
);
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
index
([
'field_a'
,
'field_b'
],
'custom_index_name'
);
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment