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 8ea65b1f
authored
Oct 07, 2014
by
Joel Trost
Committed by
Matt Broadstone
Dec 09, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Queries correct attributes specified
1 parent
11b72c6f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
12 deletions
lib/dialects/mssql/query-generator.js
lib/dialects/mssql/sql-generator.js
test/model/find.test.js
lib/dialects/mssql/query-generator.js
View file @
8ea65b1
...
@@ -435,10 +435,6 @@ module.exports = (function() {
...
@@ -435,10 +435,6 @@ module.exports = (function() {
selectQuery
:
function
(
tableName
,
options
,
model
)
{
selectQuery
:
function
(
tableName
,
options
,
model
)
{
// Enter and change at your own peril -- Mick Hansen
// Enter and change at your own peril -- Mick Hansen
//console.log('tablename', tableName);
//console.log('options', options);
//console.log('model', model.name);
//console.log(options.where);
options
=
options
||
{};
options
=
options
||
{};
var
query
=
[];
var
query
=
[];
if
(
options
.
attributes
[
0
][
0
].
fn
===
'COUNT'
){
if
(
options
.
attributes
[
0
][
0
].
fn
===
'COUNT'
){
...
...
lib/dialects/mssql/sql-generator.js
View file @
8ea65b1
...
@@ -151,13 +151,30 @@ function loadFields(attributes){
...
@@ -151,13 +151,30 @@ function loadFields(attributes){
}
}
return
attrStr
;
return
attrStr
;
}
}
function
processField
(
attribute
,
tableName
){
var
sql
=
''
;
if
(
tableName
){
sql
+=
quoteIdentifier
(
tableName
)
+
'.'
;
}
if
(
attribute
[
0
]
!==
attribute
[
1
]){
return
sql
+
quoteIdentifier
(
attribute
[
0
])
+
' AS '
+
quoteIdentifier
(
attribute
[
1
]);
}
else
{
return
sql
+
quoteIdentifier
(
attribute
[
0
]);
}
}
function
loadFieldsWithName
(
attributes
,
tableName
){
function
loadFieldsWithName
(
attributes
,
tableName
){
var
attrStr
=
[];
var
attrStr
=
[];
for
(
var
attr
in
attributes
)
{
if
(
Array
.
isArray
(
attributes
[
0
])){
if
(
tableName
){
for
(
var
i
=
0
;
i
<
attributes
.
length
;
i
++
)
{
attrStr
.
push
(
quoteIdentifier
(
tableName
)
+
"."
+
quoteIdentifier
(
attr
));
attrStr
.
push
(
processField
(
attributes
[
i
],
tableName
));
}
else
{
}
attrStr
.
push
(
quoteIdentifier
(
attr
));
}
else
{
for
(
var
attr
in
attributes
)
{
if
(
tableName
){
attrStr
.
push
(
quoteIdentifier
(
tableName
)
+
"."
+
quoteIdentifier
(
attr
));
}
else
{
attrStr
.
push
(
quoteIdentifier
(
attr
));
}
}
}
}
}
return
attrStr
.
join
(
','
);
return
attrStr
.
join
(
','
);
...
@@ -600,7 +617,7 @@ module.exports = {
...
@@ -600,7 +617,7 @@ module.exports = {
}
}
//add join table
//add join table
if
(
options
.
include
){
if
(
options
.
include
){
query
.
push
(
loadFieldsWithName
(
model
.
rawA
ttributes
,
model
.
name
));
query
.
push
(
loadFieldsWithName
(
options
.
a
ttributes
,
model
.
name
));
query
.
push
(
','
);
query
.
push
(
','
);
for
(
var
i
=
0
;
i
<
options
.
include
.
length
;
i
++
){
for
(
var
i
=
0
;
i
<
options
.
include
.
length
;
i
++
){
if
(
options
.
include
[
i
].
as
)
{
if
(
options
.
include
[
i
].
as
)
{
...
@@ -609,7 +626,8 @@ module.exports = {
...
@@ -609,7 +626,8 @@ module.exports = {
}
}
}
}
}
else
{
}
else
{
query
.
push
(
loadFieldsWithName
(
model
.
rawAttributes
));
query
.
push
(
loadFieldsWithName
(
options
.
attributes
));
//query.push(loadFieldsWithName(model.rawAttributes));
}
}
return
query
.
join
(
' '
);
return
query
.
join
(
' '
);
},
},
...
...
test/model/find.test.js
View file @
8ea65b1
...
@@ -6,6 +6,7 @@ var chai = require('chai')
...
@@ -6,6 +6,7 @@ var chai = require('chai')
,
expect
=
chai
.
expect
,
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/../support'
)
,
Support
=
require
(
__dirname
+
'/../support'
)
,
DataTypes
=
require
(
__dirname
+
"/../../lib/data-types"
)
,
DataTypes
=
require
(
__dirname
+
"/../../lib/data-types"
)
,
dialect
=
Support
.
getTestDialect
()
,
config
=
require
(
__dirname
+
"/../config/config"
)
,
config
=
require
(
__dirname
+
"/../config/config"
)
,
datetime
=
require
(
'chai-datetime'
)
,
datetime
=
require
(
'chai-datetime'
)
,
promised
=
require
(
"chai-as-promised"
)
,
promised
=
require
(
"chai-as-promised"
)
...
@@ -170,7 +171,7 @@ describe(Support.getTestDialectTeaser("Model"), function () {
...
@@ -170,7 +171,7 @@ describe(Support.getTestDialectTeaser("Model"), function () {
})
})
})
})
it
(
"should make aliased attributes available"
,
function
(
done
)
{
it
.
only
(
"should make aliased attributes available"
,
function
(
done
)
{
this
.
User
.
find
({
this
.
User
.
find
({
where
:
{
id
:
1
},
where
:
{
id
:
1
},
attributes
:
[
'id'
,
[
'username'
,
'name'
]]
attributes
:
[
'id'
,
[
'username'
,
'name'
]]
...
...
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