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 5da749c8
authored
Mar 06, 2017
by
Maks Nemisj
Committed by
Sushant
Mar 07, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
port of 791b4c04fd383bdf721e72f617f8d3270f3c789e (#7334)
1 parent
6ca925b0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
22 deletions
lib/instance.js
test/unit/instance/previous.test.js
lib/instance.js
View file @
5da749c
...
@@ -158,12 +158,11 @@ Instance.prototype.getDataValue = function(key) {
...
@@ -158,12 +158,11 @@ Instance.prototype.getDataValue = function(key) {
* @param {any} value
* @param {any} value
*/
*/
Instance
.
prototype
.
setDataValue
=
function
(
key
,
value
)
{
Instance
.
prototype
.
setDataValue
=
function
(
key
,
value
)
{
var
originalValue
=
this
.
d
ataValues
[
key
];
var
originalValue
=
this
.
_previousD
ataValues
[
key
];
if
(
!
Utils
.
isPrimitive
(
value
)
||
value
!==
originalValue
)
{
if
(
!
Utils
.
isPrimitive
(
value
)
||
value
!==
originalValue
)
{
this
.
changed
(
key
,
true
);
this
.
changed
(
key
,
true
);
}
}
this
.
_previousDataValues
[
key
]
=
originalValue
;
this
.
dataValues
[
key
]
=
value
;
this
.
dataValues
[
key
]
=
value
;
};
};
...
@@ -310,6 +309,10 @@ Instance.prototype.set = function(key, value, options) { // testhint options:non
...
@@ -310,6 +309,10 @@ Instance.prototype.set = function(key, value, options) { // testhint options:non
// If not raw, and there's a customer setter
// If not raw, and there's a customer setter
if
(
!
options
.
raw
&&
this
.
_customSetters
[
key
])
{
if
(
!
options
.
raw
&&
this
.
_customSetters
[
key
])
{
this
.
_customSetters
[
key
].
call
(
this
,
value
,
key
);
this
.
_customSetters
[
key
].
call
(
this
,
value
,
key
);
if
(
!
Utils
.
isPrimitive
(
value
)
&&
value
!==
null
||
value
!==
originalValue
)
{
this
.
_previousDataValues
[
key
]
=
originalValue
;
this
.
changed
(
key
,
true
);
}
}
else
{
}
else
{
// Check if we have included models, and if this key matches the include model names/aliases
// Check if we have included models, and if this key matches the include model names/aliases
...
...
test/unit/instance/previous.test.js
View file @
5da749c
...
@@ -11,32 +11,27 @@ describe(Support.getTestDialectTeaser('Instance'), function () {
...
@@ -11,32 +11,27 @@ describe(Support.getTestDialectTeaser('Instance'), function () {
describe
(
'previous'
,
function
()
{
describe
(
'previous'
,
function
()
{
it
(
'should return correct previous value'
,
function
()
{
it
(
'should return correct previous value'
,
function
()
{
var
Model
=
current
.
define
(
'Model'
,
{
var
Model
=
current
.
define
(
'Model'
,
{
text
:
{
text
:
DataTypes
.
STRING
,
type
:
DataTypes
.
STRING
,
textCustom
:
{
get
:
function
(
name
)
{
type
:
DataTypes
.
STRING
,
return
this
.
getDataValue
(
name
);
set
:
function
(
val
)
{
},
this
.
setDataValue
(
'textCustom'
,
val
);
set
:
function
(
value
,
name
)
{
},
this
.
setDataValue
(
name
,
value
);
get
:
function
()
{
}
this
.
getDataValue
(
'textCustom'
);
}
}
})
}
,
instance
,
shouldBeEmpty
,
shouldBeA
;
instance
=
Model
.
build
({
text
:
'a'
},
{
isNewRecord
:
false
});
});
shouldBeEmpty
=
instance
.
previous
(
'text'
);
var
instance
=
Model
.
build
({
text
:
'a'
,
textCustom
:
'abc'
});
expect
(
instance
.
previous
(
'text'
)).
to
.
be
.
not
.
ok
;
expect
(
instance
.
previous
(
'textCustom'
)).
to
.
be
.
not
.
ok
;
instance
.
set
(
'text'
,
'b'
);
instance
.
set
(
'text'
,
'b'
);
instance
.
set
(
'textCustom'
,
'def'
);
shouldBeA
=
instance
.
previous
(
'text'
);
expect
(
instance
.
previous
(
'text'
)).
to
.
be
.
equal
(
'a'
);
expect
(
instance
.
previous
(
'textCustom'
)).
to
.
be
.
equal
(
'abc'
);
expect
(
shouldBeEmpty
).
to
.
be
.
not
.
ok
;
expect
(
shouldBeA
).
to
.
be
.
equal
(
'a'
);
});
});
});
});
});
});
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