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 06383526
authored
Apr 13, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
emit errors if schema constraints invalidate Model#save
1 parent
557a1757
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
0 deletions
lib/sequelize/model-definition.js
test/Model/create.js
lib/sequelize/model-definition.js
View file @
0638352
...
@@ -101,6 +101,13 @@ ModelDefinition.prototype.build = function(values) {
...
@@ -101,6 +101,13 @@ ModelDefinition.prototype.build = function(values) {
,
self
=
this
,
self
=
this
instance
.
definition
=
this
instance
.
definition
=
this
Utils
.
_
.
map
(
this
.
attributes
,
function
(
definition
,
name
)
{
if
(
typeof
instance
[
name
]
==
'undefined'
)
{
instance
[
name
]
=
null
instance
.
addAttribute
(
name
,
null
)
}
})
return
instance
return
instance
}
}
...
...
test/Model/create.js
View file @
0638352
...
@@ -20,5 +20,20 @@ module.exports = {
...
@@ -20,5 +20,20 @@ module.exports = {
})
})
})
})
})
})
},
'it should raise an error if created object breaks definition constraints'
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
+
parseInt
(
Math
.
random
()
*
99999999
),
{
username
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
},
smth
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
}
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
create
({
username
:
'foo'
,
smth
:
null
}).
on
(
'failure'
,
function
(
err
)
{
assert
.
eql
(
err
.
message
,
"Column 'smth' cannot be null"
)
User
.
create
({
username
:
'foo'
}).
on
(
'failure'
,
function
(
err
)
{
assert
.
eql
(
err
.
message
,
"Column 'smth' cannot be null"
)
exit
()
})
})
})
}
}
}
}
\ 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