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 8210ddef
authored
Feb 09, 2014
by
Overlook Motel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor quote function to use getAssociation
1 parent
5cbd2452
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
36 deletions
lib/dialects/abstract/query-generator.js
lib/dialects/abstract/query-generator.js
View file @
8210dde
...
@@ -356,58 +356,44 @@ module.exports = (function() {
...
@@ -356,58 +356,44 @@ module.exports = (function() {
}
else
if
(
Array
.
isArray
(
obj
))
{
}
else
if
(
Array
.
isArray
(
obj
))
{
// loop through array, adding table names of models to quoted
// loop through array, adding table names of models to quoted
// (checking associations to see if names should be singularised or not)
// (checking associations to see if names should be singularised or not)
var
quoted
=
[]
var
tableNames
=
[]
,
i
,
parentAssociation
,
len
=
obj
.
length
,
len
=
obj
.
length
for
(
i
=
0
;
i
<
len
-
1
;
i
++
)
{
for
(
var
i
=
0
;
i
<
len
-
1
;
i
++
)
{
var
item
=
obj
[
i
]
var
item
=
obj
[
i
]
if
(
Utils
.
_
.
isString
(
item
)
||
item
instanceof
Utils
.
fn
||
item
instanceof
Utils
.
col
||
item
instanceof
Utils
.
literal
||
item
instanceof
Utils
.
cast
||
'raw'
in
item
)
{
if
(
Utils
.
_
.
isString
(
item
)
||
item
instanceof
Utils
.
fn
||
item
instanceof
Utils
.
col
||
item
instanceof
Utils
.
literal
||
item
instanceof
Utils
.
cast
||
'raw'
in
item
)
{
break
break
}
}
var
model
,
as
if
(
item
instanceof
daoFactory
)
{
if
(
item
instanceof
daoFactory
)
{
item
=
{
model
:
item
}
model
=
item
}
else
{
model
=
item
.
model
as
=
item
.
as
}
}
// find applicable association for linking parent to this model
// check if model provided is through table
var
model
=
item
.
model
var
association
,
as
if
(
!
as
&&
parentAssociation
&&
parentAssociation
.
through
===
model
)
{
,
associations
=
parent
.
associations
association
=
{
as
:
Utils
.
singularize
(
model
.
tableName
,
model
.
options
.
language
)}
,
association
if
(
item
.
hasOwnProperty
(
'as'
))
{
as
=
item
.
as
association
=
Utils
.
_
.
find
(
associations
,
function
(
association
,
associationName
)
{
return
association
.
target
===
model
&&
associationName
===
as
})
}
else
{
}
else
{
association
=
Utils
.
_
.
find
(
associations
,
function
(
association
,
associationName
)
{
// find applicable association for linking parent to this model
return
association
.
target
===
model
?
association
=
parent
.
getAssociation
(
model
,
as
)
associationName
===
(
association
.
doubleLinked
?
association
.
combinedName
:
(
association
.
isSingleAssociation
?
Utils
.
singularize
(
model
.
tableName
,
model
.
options
.
language
)
:
parent
.
tableName
+
model
.
tableName
)
)
:
association
.
targetAssociation
&&
association
.
targetAssociation
.
through
===
model
})
// NB association.target !== model clause below is to singularize names of through tables in hasMany-hasMany joins
as
=
(
association
&&
(
association
.
isSingleAssociation
||
association
.
target
!==
model
))
?
Utils
.
singularize
(
model
.
tableName
,
model
.
options
.
language
)
:
model
.
tableName
}
}
quoted
[
i
]
=
as
if
(
association
)
{
tableNames
[
i
]
=
association
.
as
if
(
!
association
)
{
parent
=
model
throw
new
Error
(
'\''
+
quoted
.
join
(
'.'
)
+
'\' in order / group clause is not valid association'
)
parentAssociation
=
association
}
else
{
tableNames
[
i
]
=
model
.
tableName
throw
new
Error
(
'\''
+
tableNames
.
join
(
'.'
)
+
'\' in order / group clause is not valid association'
)
}
}
parent
=
model
}
}
// add 1st string as quoted, 2nd as unquoted raw
// add 1st string as quoted, 2nd as unquoted raw
var
sql
=
(
i
>
0
?
this
.
quoteIdentifier
(
quoted
.
join
(
'.'
))
+
'.'
:
''
)
+
this
.
quote
(
obj
[
i
],
parent
,
force
)
var
sql
=
(
i
>
0
?
this
.
quoteIdentifier
(
tableNames
.
join
(
'.'
))
+
'.'
:
''
)
+
this
.
quote
(
obj
[
i
],
parent
,
force
)
if
(
i
<
len
-
1
)
{
if
(
i
<
len
-
1
)
{
sql
+=
' '
+
obj
[
i
+
1
]
sql
+=
' '
+
obj
[
i
+
1
]
}
}
...
...
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