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 83ba5dba
authored
May 17, 2015
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
💄
rename dao to instance
1 parent
110af509
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
24 deletions
lib/model.js
lib/model.js
View file @
83ba5db
...
...
@@ -1624,7 +1624,7 @@ module.exports = (function() {
values
[
this
.
_timestampAttributes
.
updatedAt
]
=
this
.
__getTimestamp
(
this
.
_timestampAttributes
.
updatedAt
);
}
var
dao
s
var
instance
s
,
valuesUse
;
return
Promise
.
try
(
function
()
{
...
...
@@ -1659,11 +1659,11 @@ module.exports = (function() {
}).
then
(
function
()
{
valuesUse
=
values
;
// Get
dao
s and run beforeUpdate hook on each record individually
// Get
instance
s and run beforeUpdate hook on each record individually
if
(
options
.
individualHooks
)
{
return
self
.
findAll
({
where
:
options
.
where
},
{
transaction
:
options
.
transaction
}).
then
(
function
(
_
dao
s
)
{
daos
=
_dao
s
;
if
(
!
dao
s
.
length
)
{
return
self
.
findAll
({
where
:
options
.
where
},
{
transaction
:
options
.
transaction
}).
then
(
function
(
_
instance
s
)
{
instances
=
_instance
s
;
if
(
!
instance
s
.
length
)
{
return
[];
}
...
...
@@ -1672,22 +1672,22 @@ module.exports = (function() {
var
changedValues
,
different
=
false
;
return
Promise
.
map
(
daos
,
function
(
dao
)
{
return
Promise
.
map
(
instances
,
function
(
instance
)
{
// Record updates in instances dataValues
Utils
.
_
.
extend
(
dao
.
dataValues
,
values
);
Utils
.
_
.
extend
(
instance
.
dataValues
,
values
);
// Set the changed fields on the instance
Utils
.
_
.
forIn
(
valuesUse
,
function
(
newValue
,
attr
)
{
if
(
newValue
!==
dao
.
_previousDataValues
[
attr
])
{
dao
.
setDataValue
(
attr
,
newValue
);
if
(
newValue
!==
instance
.
_previousDataValues
[
attr
])
{
instance
.
setDataValue
(
attr
,
newValue
);
}
});
// Run beforeUpdate hook
return
self
.
runHooks
(
'beforeUpdate'
,
dao
,
options
).
then
(
function
()
{
return
self
.
runHooks
(
'beforeUpdate'
,
instance
,
options
).
then
(
function
()
{
if
(
!
different
)
{
var
thisChangedValues
=
{};
Utils
.
_
.
forIn
(
dao
.
dataValues
,
function
(
newValue
,
attr
)
{
if
(
newValue
!==
dao
.
_previousDataValues
[
attr
])
{
Utils
.
_
.
forIn
(
instance
.
dataValues
,
function
(
newValue
,
attr
)
{
if
(
newValue
!==
instance
.
_previousDataValues
[
attr
])
{
thisChangedValues
[
attr
]
=
newValue
;
}
});
...
...
@@ -1699,10 +1699,10 @@ module.exports = (function() {
}
}
return
dao
;
return
instance
;
});
}).
then
(
function
(
_
dao
s
)
{
daos
=
_dao
s
;
}).
then
(
function
(
_
instance
s
)
{
instances
=
_instance
s
;
if
(
!
different
)
{
// Hooks do not change values or change them uniformly
...
...
@@ -1714,15 +1714,15 @@ module.exports = (function() {
}
else
{
// Hooks change values in a different way for each record
// Do not run original query but save each record individually
return
Promise
.
map
(
daos
,
function
(
dao
)
{
return
Promise
.
map
(
instances
,
function
(
instance
)
{
var
individualOptions
=
Utils
.
_
.
clone
(
options
);
delete
individualOptions
.
individualHooks
;
individualOptions
.
hooks
=
false
;
individualOptions
.
validate
=
false
;
return
dao
.
save
(
individualOptions
);
}).
tap
(
function
(
_
dao
s
)
{
daos
=
_dao
s
;
return
instance
.
save
(
individualOptions
);
}).
tap
(
function
(
_
instance
s
)
{
instances
=
_instance
s
;
});
}
});
...
...
@@ -1740,7 +1740,7 @@ module.exports = (function() {
// Run query to update all rows
return
self
.
QueryInterface
.
bulkUpdate
(
self
.
getTableName
(
options
),
valuesUse
,
options
.
where
,
options
,
self
.
tableAttributes
).
then
(
function
(
affectedRows
)
{
if
(
options
.
returning
)
{
dao
s
=
affectedRows
;
instance
s
=
affectedRows
;
return
[
affectedRows
.
length
,
affectedRows
];
}
...
...
@@ -1748,10 +1748,10 @@ module.exports = (function() {
});
}).
tap
(
function
(
result
)
{
if
(
options
.
individualHooks
)
{
return
Promise
.
map
(
daos
,
function
(
dao
)
{
return
self
.
runHooks
(
'afterUpdate'
,
dao
,
options
);
return
Promise
.
map
(
instances
,
function
(
instance
)
{
return
self
.
runHooks
(
'afterUpdate'
,
instance
,
options
);
}).
then
(
function
()
{
result
[
1
]
=
dao
s
;
result
[
1
]
=
instance
s
;
});
}
}).
tap
(
function
()
{
...
...
@@ -1763,7 +1763,7 @@ module.exports = (function() {
});
}
}).
then
(
function
(
result
)
{
// Return result in form [affectedRows,
daos] (dao
s missed off if options.individualHooks != true)
// Return result in form [affectedRows,
instances] (instance
s missed off if options.individualHooks != true)
return
result
;
});
};
...
...
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