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 08ed3756
authored
Jun 03, 2015
by
Fred K. Schott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix issue where deep-clone doesn't preserve sequelize functions
1 parent
f4aab0db
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
lib/utils.js
test/integration/model/upsert.test.js
lib/utils.js
View file @
08ed375
...
...
@@ -95,6 +95,8 @@ var Utils = module.exports = {
},
cloneDeep
:
function
(
obj
,
fn
)
{
return
lodash
.
cloneDeep
(
obj
,
function
(
elem
)
{
// Preserve special data-types like `fn` across clones. _.get() is used for checking up the prototype chain
if
(
!!
Utils
.
_
.
get
(
elem
,
'clone'
)
&&
typeof
elem
.
clone
===
'function'
)
{
return
elem
.
clone
();
}
// Unfortunately, lodash.cloneDeep doesn't preserve Buffer.isBuffer, which we have to rely on for binary data
if
(
Buffer
.
isBuffer
(
elem
))
{
return
elem
;
}
...
...
@@ -421,4 +423,8 @@ Utils.fn.prototype._isSequelizeMethod =
Utils
.
col
.
prototype
.
_isSequelizeMethod
=
Utils
.
json
.
prototype
.
_isSequelizeMethod
=
true
;
Utils
.
fn
.
prototype
.
clone
=
function
()
{
return
new
Utils
.
fn
(
this
.
fn
,
this
.
args
);
};
Utils
.
Promise
=
require
(
'./promise'
);
test/integration/model/upsert.test.js
View file @
08ed375
...
...
@@ -223,6 +223,31 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect
(
user
.
baz
).
to
.
equal
(
'oof'
);
});
});
it
(
'works with database functions'
,
function
()
{
return
this
.
User
.
upsert
({
id
:
42
,
username
:
'john'
,
foo
:
this
.
sequelize
.
fn
(
'upper'
,
'mixedCase1'
)}).
bind
(
this
).
then
(
function
(
created
)
{
if
(
dialect
===
'sqlite'
)
{
expect
(
created
).
to
.
be
.
undefined
;
}
else
{
expect
(
created
).
to
.
be
.
ok
;
}
return
this
.
sequelize
.
Promise
.
delay
(
1000
).
bind
(
this
).
then
(
function
()
{
return
this
.
User
.
upsert
({
id
:
42
,
username
:
'doe'
,
foo
:
this
.
sequelize
.
fn
(
'upper'
,
'mixedCase2'
)
});
});
}).
then
(
function
(
created
)
{
if
(
dialect
===
'sqlite'
)
{
expect
(
created
).
to
.
be
.
undefined
;
}
else
{
expect
(
created
).
not
.
to
.
be
.
ok
;
}
return
this
.
User
.
findById
(
42
);
}).
then
(
function
(
user
)
{
expect
(
user
.
createdAt
).
to
.
be
.
ok
;
expect
(
user
.
username
).
to
.
equal
(
'doe'
);
expect
(
user
.
foo
).
to
.
equal
(
'MIXEDCASE2'
);
});
});
});
}
});
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