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 0e7ce348
authored
Nov 16, 2017
by
arcdev1
Committed by
Sushant
Nov 16, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: ignore falsy attribute.unique property, fixed #8620 (#8625)
1 parent
19b620c2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
8 deletions
lib/model.js
test/unit/model/define.test.js
lib/model.js
View file @
0e7ce34
...
...
@@ -994,7 +994,7 @@ class Model {
this
.
_defaultValues
[
name
]
=
_
.
partial
(
Utils
.
toDefaultValue
,
definition
.
defaultValue
);
}
if
(
definition
.
hasOwnProperty
(
'unique'
)
&&
definition
.
unique
!==
false
)
{
if
(
definition
.
hasOwnProperty
(
'unique'
)
&&
definition
.
unique
)
{
let
idxName
;
if
(
typeof
definition
.
unique
===
'object'
&&
definition
.
unique
.
hasOwnProperty
(
'name'
))
{
idxName
=
definition
.
unique
.
name
;
...
...
@@ -4118,4 +4118,4 @@ Model.insertOrUpdate = Model.upsert;
_
.
extend
(
Model
,
associationsMixin
);
Hooks
.
applyTo
(
Model
);
module
.
exports
=
Model
;
module
.
exports
=
Model
;
\ No newline at end of file
test/unit/model/define.test.js
View file @
0e7ce34
...
...
@@ -2,18 +2,18 @@
const
chai
=
require
(
'chai'
),
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/../support'
),
Support
=
require
(
__dirname
+
'/../support'
),
DataTypes
=
require
(
'../../../lib/data-types'
),
current
=
Support
.
sequelize
;
current
=
Support
.
sequelize
;
describe
(
Support
.
getTestDialectTeaser
(
'Model'
),
()
=>
{
describe
(
'define'
,
()
=>
{
it
(
'should allow custom timestamps with underscored: true'
,
()
=>
{
const
Model
=
current
.
define
(
'User'
,
{},
{
createdAt
:
'createdAt'
,
updatedAt
:
'updatedAt'
,
timestamps
:
true
,
underscored
:
true
createdAt
:
'createdAt'
,
updatedAt
:
'updatedAt'
,
timestamps
:
true
,
underscored
:
true
});
expect
(
Model
.
rawAttributes
.
createdAt
).
to
.
be
.
defined
;
...
...
@@ -41,5 +41,22 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
}).
to
.
throw
(
"A column called 'id' was added to the attributes of 'bars' but not marked with 'primaryKey: true'"
);
});
it
(
'should defend against null or undefined "unique" attributes'
,
()
=>
{
expect
(()
=>
{
current
.
define
(
'baz'
,
{
foo
:
{
type
:
DataTypes
.
STRING
,
unique
:
null
},
bar
:
{
type
:
DataTypes
.
STRING
,
unique
:
undefined
},
bop
:
{
type
:
DataTypes
.
DATE
}
});
}).
not
.
to
.
throw
();
});
});
});
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