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 ecf511ae
authored
Sep 19, 2014
by
overlookmotel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate conforming options into own function
1 parent
391610ea
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
16 deletions
lib/model.js
lib/model.js
View file @
ecf511a
...
...
@@ -694,7 +694,8 @@ module.exports = (function() {
options
=
optClone
(
options
||
{});
if
(
typeof
options
===
'object'
)
{
if
(
options
.
hasOwnProperty
(
'include'
)
&&
options
.
include
)
{
conformOptions
(
options
);
if
(
options
.
include
)
{
hasJoin
=
true
;
validateIncludedElements
.
call
(
this
,
options
,
tableNames
);
...
...
@@ -818,6 +819,7 @@ module.exports = (function() {
*/
Model
.
prototype
.
count
=
function
(
options
)
{
options
=
Utils
.
_
.
clone
(
options
||
{});
conformOptions
(
options
);
var
col
=
'*'
;
if
(
options
.
include
)
{
...
...
@@ -935,8 +937,11 @@ module.exports = (function() {
});
}
if
(
options
.
hasOwnProperty
(
'include'
)
&&
options
.
include
&&
!
options
.
includeValidated
)
{
validateIncludedElements
.
call
(
this
,
options
);
if
(
!
options
.
includeValidated
)
{
conformOptions
(
options
);
if
(
options
.
include
)
{
validateIncludedElements
.
call
(
this
,
options
);
}
}
return
new
this
.
Instance
(
values
,
options
);
...
...
@@ -946,8 +951,11 @@ module.exports = (function() {
Model
.
prototype
.
bulkBuild
=
function
(
valueSets
,
options
)
{
options
=
options
||
{
isNewRecord
:
true
,
isDirty
:
true
};
if
(
options
.
hasOwnProperty
(
'include'
)
&&
options
.
include
&&
!
options
.
includeValidated
)
{
validateIncludedElements
.
call
(
this
,
options
);
if
(
!
options
.
includeValidated
)
{
conformOptions
(
options
);
if
(
options
.
include
)
{
validateIncludedElements
.
call
(
this
,
options
);
}
}
if
(
options
.
attributes
)
{
...
...
@@ -1703,12 +1711,10 @@ module.exports = (function() {
}.
bind
(
this
));
};
var
validateIncludedElements
=
function
(
options
,
tableNames
)
{
tableNames
=
tableNames
||
{};
options
.
includeNames
=
[];
options
.
includeMap
=
{};
options
.
hasSingleAssociation
=
false
;
options
.
hasMultiAssociation
=
false
;
var
conformOptions
=
function
(
options
)
{
if
(
!
options
.
include
)
{
return
;
}
// if include is not an array, wrap in an array
if
(
!
Array
.
isArray
(
options
.
include
))
{
...
...
@@ -1718,24 +1724,37 @@ module.exports = (function() {
return
;
}
// convert all included elements to {
M
odel: Model } form
var
includes
=
options
.
include
=
options
.
include
.
map
(
function
(
include
)
{
// convert all included elements to {
m
odel: Model } form
options
.
include
=
options
.
include
.
map
(
function
(
include
)
{
if
(
include
instanceof
Association
)
{
include
=
{
association
:
include
};
}
else
if
(
include
instanceof
Model
)
{
include
=
{
model
:
include
};
}
else
if
(
typeof
include
!==
'object'
)
{
throw
new
Error
(
'Include unexpected. Element has to be either a Model, an Association or an object.'
);
}
else
if
(
include
.
hasOwnProperty
(
'daoFactory'
))
{
}
else
{
// convert daoFactory to model (for backwards compatibility)
include
.
model
=
include
.
daoFactory
;
delete
include
.
daoFactory
;
if
(
include
.
hasOwnProperty
(
'daoFactory'
))
{
include
.
model
=
include
.
daoFactory
;
delete
include
.
daoFactory
;
}
conformOptions
(
include
);
}
return
include
;
});
};
var
validateIncludedElements
=
function
(
options
,
tableNames
)
{
tableNames
=
tableNames
||
{};
options
.
includeNames
=
[];
options
.
includeMap
=
{};
options
.
hasSingleAssociation
=
false
;
options
.
hasMultiAssociation
=
false
;
// validate all included elements
var
includes
=
options
.
include
;
for
(
var
index
=
0
;
index
<
includes
.
length
;
index
++
)
{
var
include
=
includes
[
index
];
...
...
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