Skip to content

Commit 88457bd

Browse files
committed
Fix for index names (mongodb#1137)
- fixed possiblilty to specify index names when creating them - also fixed docstring comments so code completion works properly when using IDEs
1 parent 0c5a4d7 commit 88457bd

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Jenssegers/Mongodb/Schema/Blueprint.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
77
/**
88
* The MongoConnection object for this blueprint.
99
*
10-
* @var MongoConnection
10+
* @var \Jenssegers\Mongodb\Connection
1111
*/
1212
protected $connection;
1313

1414
/**
1515
* The MongoCollection object for this blueprint.
1616
*
17-
* @var MongoCollection
17+
* @var \Jenssegers\Mongodb\Collection|\MongoDB\Collection
1818
*/
1919
protected $collection;
2020

@@ -32,7 +32,7 @@ public function __construct(Connection $connection, $collection)
3232
{
3333
$this->connection = $connection;
3434

35-
$this->collection = $connection->getCollection($collection);
35+
$this->collection = $this->connection->getCollection($collection);
3636
}
3737

3838
/**
@@ -54,6 +54,10 @@ public function index($columns = null, $name = null, $algorithm = null, $options
5454
$columns = $transform;
5555
}
5656

57+
if ($name !== null) {
58+
$options['name'] = $name;
59+
}
60+
5761
$this->collection->createIndex($columns, $options);
5862

5963
return $this;
@@ -64,7 +68,7 @@ public function index($columns = null, $name = null, $algorithm = null, $options
6468
*/
6569
public function primary($columns = null, $name = null, $algorithm = null, $options = [])
6670
{
67-
return $this->unique($columns, $options);
71+
return $this->unique($columns, $name, $algorithm, $options);
6872
}
6973

7074
/**
@@ -102,7 +106,7 @@ public function unique($columns = null, $name = null, $algorithm = null, $option
102106

103107
$options['unique'] = true;
104108

105-
$this->index($columns, null, null, $options);
109+
$this->index($columns, $name, $algorithm, $options);
106110

107111
return $this;
108112
}

0 commit comments

Comments
 (0)