Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit db0c952

Browse files
committedMay 24, 2015
Primary index is alias for unique index
1 parent fb23831 commit db0c952

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed
 

‎src/Jenssegers/Mongodb/Schema/Blueprint.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ public function index($columns = null, $options = array())
7070
return $this;
7171
}
7272

73+
/**
74+
* Specify the primary key(s) for the table.
75+
*
76+
* @param string|array $columns
77+
* @param array $options
78+
* @return \Illuminate\Support\Fluent
79+
*/
80+
public function primary($columns = null, $options = array())
81+
{
82+
return $this->unique($columns, $options);
83+
}
84+
7385
/**
7486
* Indicate that the given index should be dropped.
7587
*

‎tests/SchemaTest.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,38 @@ public function testIndex()
5252
{
5353
Schema::collection('newcollection', function ($collection)
5454
{
55-
$collection->index('mykey');
55+
$collection->index('mykey1');
5656
});
5757

58-
$index = $this->getIndex('newcollection', 'mykey');
59-
$this->assertEquals(1, $index['key']['mykey']);
58+
$index = $this->getIndex('newcollection', 'mykey1');
59+
$this->assertEquals(1, $index['key']['mykey1']);
60+
61+
Schema::collection('newcollection', function ($collection)
62+
{
63+
$collection->index(['mykey2']);
64+
});
65+
66+
$index = $this->getIndex('newcollection', 'mykey2');
67+
$this->assertEquals(1, $index['key']['mykey2']);
68+
69+
Schema::collection('newcollection', function ($collection)
70+
{
71+
$collection->string('mykey3')->index();
72+
});
6073

74+
$index = $this->getIndex('newcollection', 'mykey3');
75+
$this->assertEquals(1, $index['key']['mykey3']);
76+
}
77+
78+
public function testPrimary()
79+
{
6180
Schema::collection('newcollection', function ($collection)
6281
{
63-
$collection->index(['mykey']);
82+
$collection->string('mykey', 100)->primary();
6483
});
6584

6685
$index = $this->getIndex('newcollection', 'mykey');
67-
$this->assertEquals(1, $index['key']['mykey']);
86+
$this->assertEquals(1, $index['unique']);
6887
}
6988

7089
public function testUnique()

0 commit comments

Comments
 (0)
Please sign in to comment.