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 66fb6b67
authored
Apr 10, 2018
by
Sushant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model): dont use .attributes #4610
1 parent
fafe6ac9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
12 deletions
lib/model.js
test/integration/associations/belongs-to-many.test.js
lib/model.js
View file @
66fb6b6
...
@@ -49,9 +49,7 @@ class Model {
...
@@ -49,9 +49,7 @@ class Model {
}
}
// validateIncludedElements should have been called before this method
// validateIncludedElements should have been called before this method
static
_paranoidClause
(
model
,
options
)
{
static
_paranoidClause
(
model
,
options
=
{})
{
options
=
options
||
{};
// Apply on each include
// Apply on each include
// This should be handled before handling where conditions because of logic with returns
// This should be handled before handling where conditions because of logic with returns
// otherwise this code will never run on includes of a already conditionable where
// otherwise this code will never run on includes of a already conditionable where
...
@@ -712,9 +710,7 @@ class Model {
...
@@ -712,9 +710,7 @@ class Model {
* @return {Model}
* @return {Model}
*/
*/
static
init
(
attributes
,
options
)
{
// testhint options:none
static
init
(
attributes
,
options
=
{})
{
// testhint options:none
options
=
options
||
{};
if
(
!
options
.
sequelize
)
{
if
(
!
options
.
sequelize
)
{
throw
new
Error
(
'No Sequelize instance passed'
);
throw
new
Error
(
'No Sequelize instance passed'
);
}
}
...
@@ -1074,8 +1070,7 @@ class Model {
...
@@ -1074,8 +1070,7 @@ class Model {
}
}
this
.
prototype
.
rawAttributes
=
this
.
rawAttributes
;
this
.
prototype
.
rawAttributes
=
this
.
rawAttributes
;
this
.
prototype
.
attributes
=
Object
.
keys
(
this
.
prototype
.
rawAttributes
);
this
.
prototype
.
_isAttribute
=
key
=>
this
.
prototype
.
rawAttributes
.
hasOwnProperty
(
key
);
this
.
prototype
.
_isAttribute
=
_
.
memoize
(
key
=>
this
.
prototype
.
attributes
.
indexOf
(
key
)
!==
-
1
);
// Primary key convenience constiables
// Primary key convenience constiables
this
.
primaryKeyAttributes
=
Object
.
keys
(
this
.
primaryKeys
);
this
.
primaryKeyAttributes
=
Object
.
keys
(
this
.
primaryKeys
);
...
@@ -1085,7 +1080,7 @@ class Model {
...
@@ -1085,7 +1080,7 @@ class Model {
}
}
this
.
_hasPrimaryKeys
=
this
.
primaryKeyAttributes
.
length
>
0
;
this
.
_hasPrimaryKeys
=
this
.
primaryKeyAttributes
.
length
>
0
;
this
.
_isPrimaryKey
=
_
.
memoize
(
key
=>
this
.
primaryKeyAttributes
.
indexOf
(
key
)
!==
-
1
);
this
.
_isPrimaryKey
=
key
=>
this
.
primaryKeyAttributes
.
includes
(
key
);
}
}
/**
/**
...
@@ -2262,7 +2257,7 @@ class Model {
...
@@ -2262,7 +2257,7 @@ class Model {
}).
then
(()
=>
{
}).
then
(()
=>
{
// Map field names
// Map field names
const
updatedDataValues
=
_
.
pick
(
instance
.
dataValues
,
Object
.
keys
(
instance
.
_changed
));
const
updatedDataValues
=
_
.
pick
(
instance
.
dataValues
,
Object
.
keys
(
instance
.
_changed
));
const
insertValues
=
Utils
.
mapValueFieldNames
(
instance
.
dataValues
,
instance
.
attributes
,
this
);
const
insertValues
=
Utils
.
mapValueFieldNames
(
instance
.
dataValues
,
Object
.
keys
(
instance
.
rawAttributes
)
,
this
);
const
updateValues
=
Utils
.
mapValueFieldNames
(
updatedDataValues
,
options
.
fields
,
this
);
const
updateValues
=
Utils
.
mapValueFieldNames
(
updatedDataValues
,
options
.
fields
,
this
);
const
now
=
Utils
.
now
(
this
.
sequelize
.
options
.
dialect
);
const
now
=
Utils
.
now
(
this
.
sequelize
.
options
.
dialect
);
...
@@ -3578,7 +3573,7 @@ class Model {
...
@@ -3578,7 +3573,7 @@ class Model {
}
}
if
(
options
.
silent
===
true
&&
!
(
this
.
isNewRecord
&&
this
.
get
(
updatedAtAttr
,
{
raw
:
true
})))
{
if
(
options
.
silent
===
true
&&
!
(
this
.
isNewRecord
&&
this
.
get
(
updatedAtAttr
,
{
raw
:
true
})))
{
// UpdateAtAttr might have been added as a result of Object.keys(Model.
a
ttributes). In that case we have to remove it again
// UpdateAtAttr might have been added as a result of Object.keys(Model.
rawA
ttributes). In that case we have to remove it again
_
.
remove
(
options
.
fields
,
val
=>
val
===
updatedAtAttr
);
_
.
remove
(
options
.
fields
,
val
=>
val
===
updatedAtAttr
);
updatedAtAttr
=
false
;
updatedAtAttr
=
false
;
}
}
...
...
test/integration/associations/belongs-to-many.test.js
View file @
66fb6b6
...
@@ -76,7 +76,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
...
@@ -76,7 +76,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
return
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
then
(
john
=>
{
return
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
then
(
john
=>
{
return
john
.
getTasks
();
return
john
.
getTasks
();
}).
then
(
tasks
=>
{
}).
then
(
tasks
=>
{
tasks
[
0
].
attributes
.
forEach
(
attr
=>
{
Object
.
keys
(
tasks
[
0
].
rawAttributes
)
.
forEach
(
attr
=>
{
expect
(
tasks
[
0
]).
to
.
have
.
property
(
attr
);
expect
(
tasks
[
0
]).
to
.
have
.
property
(
attr
);
});
});
});
});
...
...
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