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 19a3010c
authored
Jan 05, 2015
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(instance): make it possible to pass createdAt and updatedAt to Model.create…
… when using silent: true
1 parent
ffaafdc2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
3 deletions
lib/instance.js
lib/model.js
test/model/create.test.js
lib/instance.js
View file @
19a3010
...
@@ -489,7 +489,7 @@ module.exports = (function() {
...
@@ -489,7 +489,7 @@ module.exports = (function() {
options
.
fields
.
push
(
updatedAtAttr
);
options
.
fields
.
push
(
updatedAtAttr
);
}
}
if
(
options
.
silent
===
true
)
{
if
(
options
.
silent
===
true
&&
!
(
this
.
isNewRecord
&&
this
.
get
(
updatedAtAttr
,
{
raw
:
true
}))
)
{
// UpdateAtAttr might have been added as a result of Object.keys(Model.attributes). In that case we have to remove it again
// UpdateAtAttr might have been added as a result of Object.keys(Model.attributes). In that case we have to remove it again
Utils
.
_
.
remove
(
options
.
fields
,
function
(
val
)
{
Utils
.
_
.
remove
(
options
.
fields
,
function
(
val
)
{
return
val
===
updatedAtAttr
;
return
val
===
updatedAtAttr
;
...
@@ -537,7 +537,7 @@ module.exports = (function() {
...
@@ -537,7 +537,7 @@ module.exports = (function() {
}
}
}
}
if
(
updatedAtAttr
)
{
if
(
updatedAtAttr
&&
!
options
.
silent
)
{
values
[
updatedAtAttr
]
=
self
.
Model
.
__getTimestamp
(
updatedAtAttr
);
values
[
updatedAtAttr
]
=
self
.
Model
.
__getTimestamp
(
updatedAtAttr
);
}
}
...
...
lib/model.js
View file @
19a3010
...
@@ -1051,7 +1051,9 @@ module.exports = (function() {
...
@@ -1051,7 +1051,9 @@ module.exports = (function() {
return
this
.
build
(
values
,
{
return
this
.
build
(
values
,
{
isNewRecord
:
true
,
isNewRecord
:
true
,
attributes
:
options
.
fields
,
attributes
:
options
.
fields
,
include
:
options
.
include
include
:
options
.
include
,
raw
:
options
.
raw
,
silent
:
options
.
silent
}).
save
(
options
);
}).
save
(
options
);
};
};
...
...
test/model/create.test.js
View file @
19a3010
...
@@ -294,6 +294,38 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -294,6 +294,38 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
});
});
it
(
'should be able to set createdAt and updatedAt if using silent: true'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'user'
,
{
name
:
DataTypes
.
STRING
},
{
timestamps
:
true
});
var
createdAt
=
new
Date
(
2012
,
10
,
10
,
10
,
10
,
10
);
var
updatedAt
=
new
Date
(
2011
,
11
,
11
,
11
,
11
,
11
);
return
User
.
sync
({
force
:
true
}).
then
(
function
()
{
return
User
.
create
({
createdAt
:
createdAt
,
updatedAt
:
updatedAt
},
{
silent
:
true
}).
then
(
function
(
user
)
{
expect
(
createdAt
.
getTime
()).
to
.
equal
(
user
.
get
(
'createdAt'
).
getTime
());
expect
(
updatedAt
.
getTime
()).
to
.
equal
(
user
.
get
(
'updatedAt'
).
getTime
());
return
User
.
findOne
({
updatedAt
:
{
ne
:
null
}
}).
then
(
function
(
user
)
{
expect
(
createdAt
.
getTime
()).
to
.
equal
(
user
.
get
(
'createdAt'
).
getTime
());
expect
(
updatedAt
.
getTime
()).
to
.
equal
(
user
.
get
(
'updatedAt'
).
getTime
());
});
});
});
});
if
(
current
.
dialect
.
supports
.
transactions
)
{
if
(
current
.
dialect
.
supports
.
transactions
)
{
it
(
'supports transactions'
,
function
(
done
)
{
it
(
'supports transactions'
,
function
(
done
)
{
var
self
=
this
;
var
self
=
this
;
...
...
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