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 454cf48e
authored
Mar 09, 2019
by
Sushant
Committed by
GitHub
Mar 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model): throw for invalid include type (#10527)
1 parent
0b5aa71f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
32 deletions
lib/model.js
package.json
test/unit/model/include.test.js
lib/model.js
View file @
454cf48
...
...
@@ -324,48 +324,56 @@ class Model {
}
static
_conformInclude
(
include
,
self
)
{
let
model
;
if
(
include
)
{
let
model
;
if
(
include
.
_pseudo
)
return
include
;
if
(
include
.
_pseudo
)
return
include
;
include
=
this
.
_transformStringAssociation
(
include
,
self
);
include
=
this
.
_transformStringAssociation
(
include
,
self
);
if
(
include
instanceof
Association
)
{
if
(
self
&&
include
.
target
.
name
===
self
.
name
)
{
model
=
include
.
source
;
}
else
{
model
=
include
.
target
;
if
(
include
instanceof
Association
)
{
if
(
self
&&
include
.
target
.
name
===
self
.
name
)
{
model
=
include
.
source
;
}
else
{
model
=
include
.
target
;
}
return
{
model
,
association
:
include
,
as
:
include
.
as
};
}
return
{
model
,
association
:
include
,
as
:
include
.
as
};
}
if
(
include
.
prototype
&&
include
.
prototype
instanceof
Model
)
{
return
{
model
:
include
};
}
if
(
_
.
isPlainObject
(
include
))
{
if
(
include
.
association
)
{
if
(
include
.
prototype
&&
include
.
prototype
instanceof
Model
)
{
return
{
model
:
include
};
}
include
.
association
=
this
.
_transformStringAssociation
(
include
.
association
,
self
);
if
(
_
.
isPlainObject
(
include
))
{
if
(
include
.
association
)
{
include
.
association
=
this
.
_transformStringAssociation
(
include
.
association
,
self
);
if
(
self
&&
include
.
association
.
target
.
name
===
self
.
name
)
{
model
=
include
.
association
.
source
;
}
else
{
model
=
include
.
association
.
target
;
if
(
self
&&
include
.
association
.
target
.
name
===
self
.
name
)
{
model
=
include
.
association
.
source
;
}
else
{
model
=
include
.
association
.
target
;
}
if
(
!
include
.
model
)
include
.
model
=
model
;
if
(
!
include
.
as
)
include
.
as
=
include
.
association
.
as
;
this
.
_conformOptions
(
include
,
model
);
return
include
;
}
if
(
!
include
.
model
)
{
include
.
model
=
model
;
if
(
include
.
model
)
{
this
.
_conformOptions
(
include
,
include
.
model
);
return
include
;
}
if
(
!
include
.
as
)
{
include
.
as
=
include
.
association
.
as
;
if
(
include
.
all
)
{
this
.
_conformOptions
(
include
);
return
include
;
}
}
else
{
model
=
include
.
model
;
}
this
.
_conformOptions
(
include
,
model
);
return
include
;
}
throw
new
Error
(
'Include unexpected. Element has to be either a Model, an Association or an object.'
);
}
...
...
package.json
View file @
454cf48
...
...
@@ -67,7 +67,6 @@
"eslint"
:
"^5.15.0"
,
"eslint-plugin-jsdoc"
:
"^4.1.1"
,
"eslint-plugin-mocha"
:
"^5.2.1"
,
"hints"
:
"^1.x"
,
"husky"
:
"^1.3.1"
,
"js-combinatorics"
:
"^0.5.4"
,
"lcov-result-merger"
:
"^3.0.0"
,
...
...
test/unit/model/include.test.js
View file @
454cf48
...
...
@@ -8,7 +8,6 @@ const chai = require('chai'),
describe
(
Support
.
getTestDialectTeaser
(
'Model'
),
()
=>
{
describe
(
'all'
,
()
=>
{
const
Referral
=
current
.
define
(
'referal'
);
Referral
.
belongsTo
(
Referral
);
...
...
@@ -252,7 +251,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
describe
(
'_conformInclude
: string alias
'
,
()
=>
{
describe
(
'_conformInclude'
,
()
=>
{
it
(
'should expand association from string alias'
,
function
()
{
const
options
=
{
include
:
[
'Owner'
]
...
...
@@ -282,6 +281,30 @@ describe(Support.getTestDialectTeaser('Model'), () => {
as
:
'Owner'
});
});
it
(
'should throw an error if invalid model is passed'
,
function
()
{
const
options
=
{
include
:
[{
model
:
null
}]
};
expect
(()
=>
{
Sequelize
.
Model
.
_conformOptions
(
options
,
this
.
Company
);
}).
to
.
throw
(
'Include unexpected. Element has to be either a Model, an Association or an object.'
);
});
it
(
'should throw an error if invalid association is passed'
,
function
()
{
const
options
=
{
include
:
[{
association
:
null
}]
};
expect
(()
=>
{
Sequelize
.
Model
.
_conformOptions
(
options
,
this
.
Company
);
}).
to
.
throw
(
'Include unexpected. Element has to be either a Model, an Association or an object.'
);
});
});
describe
(
'_getIncludedAssociation'
,
()
=>
{
...
...
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