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 d14615a7
authored
May 18, 2016
by
Luc Verdier
Committed by
Jan Aagaard Meier
May 18, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move afterCreate hook (#5829)
1 parent
c29c713a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
14 deletions
changelog.md
lib/instance.js
test/integration/model/create/include.test.js
changelog.md
View file @
d14615a
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
-
[
FIXED
]
Add
`raw`
support to
`instance.get()`
[
#5815
](
https://github.com/sequelize/sequelize/issues/5815
)
-
[
FIXED
]
Add
`raw`
support to
`instance.get()`
[
#5815
](
https://github.com/sequelize/sequelize/issues/5815
)
-
[
ADDED
]
Compare
`deletedAt`
against current timestamp when using paranoid
[
#5880
](
https://github.com/sequelize/sequelize/pull/5880
)
-
[
ADDED
]
Compare
`deletedAt`
against current timestamp when using paranoid
[
#5880
](
https://github.com/sequelize/sequelize/pull/5880
)
-
[
FIXED
]
`BIGINT`
gets truncated
[
#5176
](
https://github.com/sequelize/sequelize/issues/5176
)
-
[
FIXED
]
`BIGINT`
gets truncated
[
#5176
](
https://github.com/sequelize/sequelize/issues/5176
)
-
[
FIXED
]
Trigger afterCreate hook after all nested includes (for hasMany or belongsToMany associations) have been created to be consistent with hasOne.
-
[
REMOVED
]
Support for
`pool:false`
-
[
REMOVED
]
Support for
`pool:false`
## BC breaks:
## BC breaks:
...
...
lib/instance.js
View file @
d14615a
...
@@ -675,20 +675,6 @@ Instance.prototype.save = function(options) {
...
@@ -675,20 +675,6 @@ Instance.prototype.save = function(options) {
return
result
;
return
result
;
})
})
.
tap
(
function
(
result
)
{
.
tap
(
function
(
result
)
{
// Run after hook
if
(
options
.
hooks
)
{
return
self
.
Model
.
runHooks
(
'after'
+
hook
,
result
,
options
);
}
})
.
then
(
function
(
result
)
{
options
.
fields
.
forEach
(
function
(
field
)
{
result
.
_previousDataValues
[
field
]
=
result
.
dataValues
[
field
];
self
.
changed
(
field
,
false
);
});
self
.
isNewRecord
=
false
;
return
result
;
})
.
tap
(
function
()
{
if
(
!
wasNewRecord
)
return
self
;
if
(
!
wasNewRecord
)
return
self
;
if
(
!
self
.
$options
.
include
||
!
self
.
$options
.
include
.
length
)
return
self
;
if
(
!
self
.
$options
.
include
||
!
self
.
$options
.
include
.
length
)
return
self
;
...
@@ -725,6 +711,20 @@ Instance.prototype.save = function(options) {
...
@@ -725,6 +711,20 @@ Instance.prototype.save = function(options) {
}
}
});
});
});
});
})
.
tap
(
function
(
result
)
{
// Run after hook
if
(
options
.
hooks
)
{
return
self
.
Model
.
runHooks
(
'after'
+
hook
,
result
,
options
);
}
})
.
then
(
function
(
result
)
{
options
.
fields
.
forEach
(
function
(
field
)
{
result
.
_previousDataValues
[
field
]
=
result
.
dataValues
[
field
];
self
.
changed
(
field
,
false
);
});
self
.
isNewRecord
=
false
;
return
result
;
});
});
});
});
});
});
...
...
test/integration/model/create/include.test.js
View file @
d14615a
...
@@ -13,6 +13,12 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -13,6 +13,12 @@ describe(Support.getTestDialectTeaser('Model'), function() {
it
(
'should create data for BelongsTo relations'
,
function
()
{
it
(
'should create data for BelongsTo relations'
,
function
()
{
var
Product
=
this
.
sequelize
.
define
(
'Product'
,
{
var
Product
=
this
.
sequelize
.
define
(
'Product'
,
{
title
:
Sequelize
.
STRING
title
:
Sequelize
.
STRING
},
{
hooks
:
{
afterCreate
:
function
(
product
)
{
product
.
isIncludeCreatedOnAfterCreate
=
!!
(
product
.
User
&&
product
.
User
.
id
);
}
}
});
});
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
first_name
:
Sequelize
.
STRING
,
first_name
:
Sequelize
.
STRING
,
...
@@ -40,6 +46,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -40,6 +46,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
myOption
:
'option'
myOption
:
'option'
}]
}]
}).
then
(
function
(
savedProduct
)
{
}).
then
(
function
(
savedProduct
)
{
expect
(
savedProduct
.
isIncludeCreatedOnAfterCreate
).
to
.
be
.
true
;
expect
(
savedProduct
.
User
.
createOptions
.
myOption
).
to
.
be
.
equal
(
'option'
);
expect
(
savedProduct
.
User
.
createOptions
.
myOption
).
to
.
be
.
equal
(
'option'
);
expect
(
savedProduct
.
User
.
createOptions
.
parentRecord
).
to
.
be
.
equal
(
savedProduct
);
expect
(
savedProduct
.
User
.
createOptions
.
parentRecord
).
to
.
be
.
equal
(
savedProduct
);
return
Product
.
findOne
({
return
Product
.
findOne
({
...
@@ -90,6 +97,15 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -90,6 +97,15 @@ describe(Support.getTestDialectTeaser('Model'), function() {
it
(
'should create data for HasMany relations'
,
function
()
{
it
(
'should create data for HasMany relations'
,
function
()
{
var
Product
=
this
.
sequelize
.
define
(
'Product'
,
{
var
Product
=
this
.
sequelize
.
define
(
'Product'
,
{
title
:
Sequelize
.
STRING
title
:
Sequelize
.
STRING
},
{
hooks
:
{
afterCreate
:
function
(
product
)
{
product
.
areIncludesCreatedOnAfterCreate
=
product
.
Tags
&&
product
.
Tags
.
every
(
function
(
tag
)
{
return
!!
tag
.
id
;
});
}
}
});
});
var
Tag
=
this
.
sequelize
.
define
(
'Tag'
,
{
var
Tag
=
this
.
sequelize
.
define
(
'Tag'
,
{
name
:
Sequelize
.
STRING
name
:
Sequelize
.
STRING
...
@@ -117,6 +133,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -117,6 +133,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
myOption
:
'option'
myOption
:
'option'
}]
}]
}).
then
(
function
(
savedProduct
)
{
}).
then
(
function
(
savedProduct
)
{
expect
(
savedProduct
.
areIncludesCreatedOnAfterCreate
).
to
.
be
.
true
;
expect
(
savedProduct
.
Tags
[
0
].
createOptions
.
myOption
).
to
.
be
.
equal
(
'option'
);
expect
(
savedProduct
.
Tags
[
0
].
createOptions
.
parentRecord
).
to
.
be
.
equal
(
savedProduct
);
expect
(
savedProduct
.
Tags
[
1
].
createOptions
.
myOption
).
to
.
be
.
equal
(
'option'
);
expect
(
savedProduct
.
Tags
[
1
].
createOptions
.
parentRecord
).
to
.
be
.
equal
(
savedProduct
);
return
Product
.
find
({
return
Product
.
find
({
where
:
{
id
:
savedProduct
.
id
},
where
:
{
id
:
savedProduct
.
id
},
include
:
[
Tag
]
include
:
[
Tag
]
...
@@ -224,6 +245,15 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -224,6 +245,15 @@ describe(Support.getTestDialectTeaser('Model'), function() {
it
(
'should create data for BelongsToMany relations'
,
function
()
{
it
(
'should create data for BelongsToMany relations'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
username
:
DataTypes
.
STRING
},{
hooks
:
{
afterCreate
:
function
(
user
)
{
user
.
areIncludesCreatedOnAfterCreate
=
user
.
Tasks
&&
user
.
Tasks
.
every
(
function
(
task
)
{
return
!!
task
.
id
;
});
}
}
});
});
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
...
@@ -253,6 +283,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -253,6 +283,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
myOption
:
'option'
myOption
:
'option'
}]
}]
}).
then
(
function
(
savedUser
)
{
}).
then
(
function
(
savedUser
)
{
expect
(
savedUser
.
areIncludesCreatedOnAfterCreate
).
to
.
be
.
true
;
expect
(
savedUser
.
Tasks
[
0
].
createOptions
.
myOption
).
to
.
be
.
equal
(
'option'
);
expect
(
savedUser
.
Tasks
[
0
].
createOptions
.
myOption
).
to
.
be
.
equal
(
'option'
);
expect
(
savedUser
.
Tasks
[
0
].
createOptions
.
parentRecord
).
to
.
be
.
equal
(
savedUser
);
expect
(
savedUser
.
Tasks
[
0
].
createOptions
.
parentRecord
).
to
.
be
.
equal
(
savedUser
);
expect
(
savedUser
.
Tasks
[
1
].
createOptions
.
myOption
).
to
.
be
.
equal
(
'option'
);
expect
(
savedUser
.
Tasks
[
1
].
createOptions
.
myOption
).
to
.
be
.
equal
(
'option'
);
...
...
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