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 5cbd2452
authored
Feb 09, 2014
by
Overlook Motel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor validateIncludedElement to utilise altered getAssociation
1 parent
2ed685be
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
27 deletions
lib/dao-factory.js
lib/dao-factory.js
View file @
5cbd245
...
...
@@ -1349,21 +1349,22 @@ module.exports = (function() {
var
validateIncludedElement
=
function
(
include
,
parent
)
{
if
(
include
instanceof
DAOFactory
)
{
include
=
{
daoFactory
:
include
,
as
:
include
.
tableName
}
include
=
{
daoFactory
:
include
}
}
if
(
typeof
parent
===
"undefined"
)
{
parent
=
this
}
if
(
typeof
include
===
'object'
)
{
if
(
typeof
include
!==
'object'
)
{
throw
new
Error
(
'Include unexpected. Element has to be either an instance of DAOFactory or an object.'
)
}
if
(
include
.
hasOwnProperty
(
'model'
))
{
include
.
daoFactory
=
include
.
model
delete
include
.
model
}
if
(
!
include
.
hasOwnProperty
(
'as'
))
{
include
.
as
=
include
.
daoFactory
.
tableName
}
else
if
(
!
include
.
hasOwnProperty
(
'daoFactory'
))
{
throw
new
Error
(
'Include malformed. Expected attributes: daoFactory, as!'
)
}
if
(
include
.
hasOwnProperty
(
'attributes'
))
{
...
...
@@ -1384,18 +1385,11 @@ module.exports = (function() {
// pseudo include just needed the attribute logic, return
if
(
include
.
_pseudo
)
return
include
if
(
include
.
hasOwnProperty
(
'daoFactory'
)
&&
(
include
.
hasOwnProperty
(
'as'
)))
{
var
usesAlias
=
(
include
.
as
!==
include
.
daoFactory
.
tableName
)
,
association
=
(
usesAlias
?
parent
.
getAssociationByAlias
(
include
.
as
)
:
parent
.
getAssociation
(
include
.
daoFactory
))
// If single (1:1) association, we singularize the alias, so it will match the automatically generated alias of belongsTo/HasOne
if
(
association
&&
!
usesAlias
&&
association
.
isSingleAssociation
)
{
include
.
as
=
Utils
.
singularize
(
include
.
daoFactory
.
tableName
,
include
.
daoFactory
.
options
.
language
)
}
// check if the current daoFactory is actually associated with the passed daoFactory - or it's a pseudo include
if
(
association
&&
(
!
association
.
options
.
as
||
(
association
.
options
.
as
===
include
.
as
)))
{
var
association
=
parent
.
getAssociation
(
include
.
daoFactory
,
include
.
as
)
if
(
association
)
{
include
.
association
=
association
include
.
as
=
association
.
as
// If through, we create a pseudo child include, to ease our parsing later on
if
(
Object
(
include
.
association
.
through
)
===
include
.
association
.
through
)
{
...
...
@@ -1415,10 +1409,7 @@ module.exports = (function() {
}
if
(
include
.
required
===
undefined
)
{
include
.
required
=
false
if
(
include
.
where
)
{
include
.
required
=
true
}
include
.
required
=
!!
include
.
where
}
// Validate child includes
...
...
@@ -1430,7 +1421,7 @@ module.exports = (function() {
}
else
{
var
msg
=
include
.
daoFactory
.
name
if
(
usesAli
as
)
{
if
(
include
.
as
)
{
msg
+=
" ("
+
include
.
as
+
")"
}
...
...
@@ -1438,12 +1429,6 @@ module.exports = (function() {
throw
new
Error
(
msg
)
}
}
else
{
throw
new
Error
(
'Include malformed. Expected attributes: daoFactory, as!'
)
}
}
else
{
throw
new
Error
(
'Include unexpected. Element has to be either an instance of DAOFactory or an object.'
)
}
}
var
replaceReferencesWithTableNames
=
function
(
attributes
)
{
...
...
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