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 ef18710d
authored
Mar 26, 2019
by
u9r52sld
Committed by
Sushant
Mar 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(associations): correctly parse include options (#10580)
1 parent
83f696ad
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
20 deletions
lib/model.js
test/integration/model/scope/associations.test.js
test/unit/model/include.test.js
test/unit/sql/generateJoin.test.js
lib/model.js
View file @
ef18710
...
@@ -90,7 +90,7 @@ class Model {
...
@@ -90,7 +90,7 @@ class Model {
}
}
if
(
!
options
.
includeValidated
)
{
if
(
!
options
.
includeValidated
)
{
this
.
constructor
.
_conform
Option
s
(
options
,
this
.
constructor
);
this
.
constructor
.
_conform
Include
s
(
options
,
this
.
constructor
);
if
(
options
.
include
)
{
if
(
options
.
include
)
{
this
.
constructor
.
_expandIncludeAll
(
options
);
this
.
constructor
.
_expandIncludeAll
(
options
);
this
.
constructor
.
_validateIncludedElements
(
options
);
this
.
constructor
.
_validateIncludedElements
(
options
);
...
@@ -306,14 +306,9 @@ class Model {
...
@@ -306,14 +306,9 @@ class Model {
}
}
}
}
static
_conformOptions
(
options
,
self
)
{
static
_conformIncludes
(
options
,
self
)
{
if
(
self
)
{
if
(
!
options
.
include
)
return
;
self
.
_expandAttributes
(
options
);
}
if
(
!
options
.
include
)
{
return
;
}
// if include is not an array, wrap in an array
// if include is not an array, wrap in an array
if
(
!
Array
.
isArray
(
options
.
include
))
{
if
(
!
Array
.
isArray
(
options
.
include
))
{
options
.
include
=
[
options
.
include
];
options
.
include
=
[
options
.
include
];
...
@@ -371,17 +366,17 @@ class Model {
...
@@ -371,17 +366,17 @@ class Model {
if
(
!
include
.
model
)
include
.
model
=
model
;
if
(
!
include
.
model
)
include
.
model
=
model
;
if
(
!
include
.
as
)
include
.
as
=
include
.
association
.
as
;
if
(
!
include
.
as
)
include
.
as
=
include
.
association
.
as
;
this
.
_conform
Option
s
(
include
,
model
);
this
.
_conform
Include
s
(
include
,
model
);
return
include
;
return
include
;
}
}
if
(
include
.
model
)
{
if
(
include
.
model
)
{
this
.
_conform
Option
s
(
include
,
include
.
model
);
this
.
_conform
Include
s
(
include
,
include
.
model
);
return
include
;
return
include
;
}
}
if
(
include
.
all
)
{
if
(
include
.
all
)
{
this
.
_conform
Option
s
(
include
);
this
.
_conform
Include
s
(
include
);
return
include
;
return
include
;
}
}
}
}
...
@@ -789,7 +784,7 @@ class Model {
...
@@ -789,7 +784,7 @@ class Model {
static
_baseMerge
(...
args
)
{
static
_baseMerge
(...
args
)
{
_
.
assignWith
(...
args
);
_
.
assignWith
(...
args
);
this
.
_conform
Options
(
args
[
0
]
);
this
.
_conform
Includes
(
args
[
0
],
this
);
this
.
_uniqIncludes
(
args
[
0
]);
this
.
_uniqIncludes
(
args
[
0
]);
return
args
[
0
];
return
args
[
0
];
}
}
...
@@ -1700,7 +1695,8 @@ class Model {
...
@@ -1700,7 +1695,8 @@ class Model {
return
this
.
runHooks
(
'beforeFind'
,
options
);
return
this
.
runHooks
(
'beforeFind'
,
options
);
}
}
}).
then
(()
=>
{
}).
then
(()
=>
{
this
.
_conformOptions
(
options
,
this
);
this
.
_conformIncludes
(
options
,
this
);
this
.
_expandAttributes
(
options
);
this
.
_expandIncludeAll
(
options
);
this
.
_expandIncludeAll
(
options
);
if
(
options
.
hooks
)
{
if
(
options
.
hooks
)
{
...
@@ -1936,7 +1932,7 @@ class Model {
...
@@ -1936,7 +1932,7 @@ class Model {
options
=
Utils
.
cloneDeep
(
options
);
options
=
Utils
.
cloneDeep
(
options
);
this
.
_injectScope
(
options
);
this
.
_injectScope
(
options
);
this
.
_conform
Option
s
(
options
,
this
);
this
.
_conform
Include
s
(
options
,
this
);
if
(
options
.
include
)
{
if
(
options
.
include
)
{
this
.
_expandIncludeAll
(
options
);
this
.
_expandIncludeAll
(
options
);
...
@@ -2149,7 +2145,7 @@ class Model {
...
@@ -2149,7 +2145,7 @@ class Model {
},
options
||
{});
},
options
||
{});
if
(
!
options
.
includeValidated
)
{
if
(
!
options
.
includeValidated
)
{
this
.
_conform
Option
s
(
options
,
this
);
this
.
_conform
Include
s
(
options
,
this
);
if
(
options
.
include
)
{
if
(
options
.
include
)
{
this
.
_expandIncludeAll
(
options
);
this
.
_expandIncludeAll
(
options
);
this
.
_validateIncludedElements
(
options
);
this
.
_validateIncludedElements
(
options
);
...
...
test/integration/model/scope/associations.test.js
View file @
ef18710
...
@@ -418,6 +418,46 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -418,6 +418,46 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect
(
user
.
dataValues
).
not
.
to
.
have
.
property
(
'secret'
);
expect
(
user
.
dataValues
).
not
.
to
.
have
.
property
(
'secret'
);
});
});
});
});
it
(
'should not throw error'
,
function
()
{
const
Clientfile
=
this
.
sequelize
.
define
(
'clientfile'
);
const
Mission
=
this
.
sequelize
.
define
(
'mission'
,
{
secret
:
Sequelize
.
STRING
});
const
Building
=
this
.
sequelize
.
define
(
'building'
);
const
MissionAssociation
=
Clientfile
.
hasOne
(
Mission
);
const
BuildingAssociation
=
Clientfile
.
hasOne
(
Building
);
return
this
.
sequelize
.
sync
({
force
:
true
})
.
then
(()
=>
{
return
Clientfile
.
findAll
({
include
:
[
{
association
:
'mission'
,
where
:
{
secret
:
'foo'
}
},
{
association
:
'building'
}
]
});
})
.
then
(()
=>
{
return
Clientfile
.
findAll
({
include
:
[
{
association
:
MissionAssociation
,
where
:
{
secret
:
'foo'
}
},
{
association
:
BuildingAssociation
}
]
});
});
});
});
});
});
});
});
});
...
...
test/unit/model/include.test.js
View file @
ef18710
...
@@ -256,7 +256,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -256,7 +256,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
const
options
=
{
const
options
=
{
include
:
[
'Owner'
]
include
:
[
'Owner'
]
};
};
Sequelize
.
Model
.
_conform
Option
s
(
options
,
this
.
Company
);
Sequelize
.
Model
.
_conform
Include
s
(
options
,
this
.
Company
);
expect
(
options
.
include
[
0
]).
to
.
deep
.
equal
({
expect
(
options
.
include
[
0
]).
to
.
deep
.
equal
({
model
:
this
.
User
,
model
:
this
.
User
,
...
@@ -272,7 +272,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -272,7 +272,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
attributes
:
[
'id'
]
attributes
:
[
'id'
]
}]
}]
};
};
Sequelize
.
Model
.
_conform
Option
s
(
options
,
this
.
Company
);
Sequelize
.
Model
.
_conform
Include
s
(
options
,
this
.
Company
);
expect
(
options
.
include
[
0
]).
to
.
deep
.
equal
({
expect
(
options
.
include
[
0
]).
to
.
deep
.
equal
({
model
:
this
.
User
,
model
:
this
.
User
,
...
@@ -290,7 +290,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -290,7 +290,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
};
};
expect
(()
=>
{
expect
(()
=>
{
Sequelize
.
Model
.
_conform
Option
s
(
options
,
this
.
Company
);
Sequelize
.
Model
.
_conform
Include
s
(
options
,
this
.
Company
);
}).
to
.
throw
(
'Include unexpected. Element has to be either a Model, an Association or an object.'
);
}).
to
.
throw
(
'Include unexpected. Element has to be either a Model, an Association or an object.'
);
});
});
...
@@ -302,7 +302,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -302,7 +302,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
};
};
expect
(()
=>
{
expect
(()
=>
{
Sequelize
.
Model
.
_conform
Option
s
(
options
,
this
.
Company
);
Sequelize
.
Model
.
_conform
Include
s
(
options
,
this
.
Company
);
}).
to
.
throw
(
'Include unexpected. Element has to be either a Model, an Association or an object.'
);
}).
to
.
throw
(
'Include unexpected. Element has to be either a Model, an Association or an object.'
);
});
});
});
});
...
...
test/unit/sql/generateJoin.test.js
View file @
ef18710
...
@@ -18,7 +18,7 @@ describe(Support.getTestDialectTeaser('SQL'), () => {
...
@@ -18,7 +18,7 @@ describe(Support.getTestDialectTeaser('SQL'), () => {
const
name
=
`
${
path
}
,
${
util
.
inspect
(
options
,
{
depth
:
10
})}
`
;
const
name
=
`
${
path
}
,
${
util
.
inspect
(
options
,
{
depth
:
10
})}
`
;
Sequelize
.
Model
.
_conform
Option
s
(
options
);
Sequelize
.
Model
.
_conform
Include
s
(
options
);
options
=
Sequelize
.
Model
.
_validateIncludedElements
(
options
);
options
=
Sequelize
.
Model
.
_validateIncludedElements
(
options
);
const
include
=
_
.
at
(
options
,
path
)[
0
];
const
include
=
_
.
at
(
options
,
path
)[
0
];
...
...
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