Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 7764212a
authored
Feb 21, 2016
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug(indexes) Set unique: true when type = UNIQUE. Closes #5351
1 parent
a49a7c1d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
13 deletions
changelog.md
lib/dialects/abstract/query-generator.js
lib/model.js
test/unit/model/indexes.test.js
changelog.md
View file @
7764212
# Future
-
[
ADDED
]
`beforeCount`
hook
[
#5209
](
https://github.com/sequelize/sequelize/pull/5209
)
-
[
ADDED
]
`validationFailed`
hook
[
#1626
](
https://github.com/sequelize/sequelize/issues/1626
)
-
[
FIXED
]
Mark index as
`unique: true`
when
`type: 'UNIQUE'`
. Fixes
[
#5351
](
https://github.com/sequelize/sequelize/issues/5351
)
# 3.19.3
-
[
FIXED
]
`updatedAt`
and
`createdAt`
values are now set before validation
[
#5367
](
https://github.com/sequelize/sequelize/pull/5367
)
...
...
lib/dialects/abstract/query-generator.js
View file @
7764212
...
...
@@ -662,15 +662,7 @@ var QueryGenerator = {
options
=
this
.
nameIndexes
([
options
],
options
.
prefix
)[
0
];
}
options
=
Utils
.
_
.
defaults
(
options
,
{
type
:
''
,
parser
:
null
});
if
(
options
.
type
.
toLowerCase
()
===
'unique'
)
{
options
.
unique
=
true
;
delete
options
.
type
;
}
options
=
Model
.
prototype
.
$conformIndex
(
options
);
if
(
!
this
.
_dialect
.
supports
.
index
.
type
)
{
delete
options
.
type
;
...
...
@@ -686,8 +678,6 @@ var QueryGenerator = {
tableName
=
this
.
quoteTable
(
tableName
);
}
var
concurrently
=
this
.
_dialect
.
supports
.
index
.
concurrently
&&
options
.
concurrently
?
'CONCURRENTLY'
:
undefined
,
ind
;
if
(
this
.
_dialect
.
supports
.
indexViaAlter
)
{
...
...
lib/model.js
View file @
7764212
...
...
@@ -728,12 +728,27 @@ Model.prototype.init = function(modelManager) {
}
}.
bind
(
this
));
this
.
options
.
indexes
=
this
.
options
.
indexes
.
map
(
this
.
$conformIndex
);
this
.
Instance
.
prototype
.
$Model
=
this
.
Instance
.
prototype
.
Model
=
this
;
return
this
;
};
Model
.
prototype
.
$conformIndex
=
function
(
index
)
{
index
=
_
.
defaults
(
index
,
{
type
:
''
,
parser
:
null
});
if
(
index
.
type
&&
index
.
type
.
toLowerCase
()
===
'unique'
)
{
index
.
unique
=
true
;
delete
index
.
type
;
}
return
index
;
};
Model
.
prototype
.
refreshAttributes
=
function
()
{
var
self
=
this
,
attributeManipulation
=
{};
...
...
test/unit/model/indexes.test.js
View file @
7764212
...
...
@@ -23,5 +23,21 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect
(
Model
.
options
.
indexes
[
0
].
fields
).
to
.
eql
([
'data'
]);
expect
(
Model
.
options
.
indexes
[
0
].
using
).
to
.
equal
(
'gin'
);
});
it
(
'should set the unique property when type is unique'
,
function
()
{
var
Model
=
current
.
define
(
'm'
,
{},
{
indexes
:
[
{
type
:
'unique'
},
{
type
:
'UNIQUE'
}
]
});
expect
(
Model
.
options
.
indexes
[
0
].
unique
).
to
.
eql
(
true
);
expect
(
Model
.
options
.
indexes
[
1
].
unique
).
to
.
eql
(
true
);
});
});
});
\ No newline at end of file
});
Write
Preview
Markdown
is supported
Attach a file
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 post a comment