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 0ee89ca8
authored
Aug 18, 2013
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow filtering of attributes for eager loading
1 parent
6a9c8509
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
6 deletions
lib/dao-factory.js
lib/dialects/mysql/query-generator.js
lib/dialects/postgres/query-generator.js
lib/dialects/sqlite/query-generator.js
test/dao-factory.test.js
lib/dao-factory.js
View file @
0ee89ca
...
@@ -169,7 +169,7 @@ module.exports = (function() {
...
@@ -169,7 +169,7 @@ module.exports = (function() {
this
.
DAO
.
prototype
.
__factory
=
this
this
.
DAO
.
prototype
.
__factory
=
this
this
.
DAO
.
prototype
.
hasDefaultValues
=
!
Utils
.
_
.
isEmpty
(
this
.
DAO
.
prototype
.
defaultValues
)
this
.
DAO
.
prototype
.
hasDefaultValues
=
!
Utils
.
_
.
isEmpty
(
this
.
DAO
.
prototype
.
defaultValues
)
return
this
return
this
}
}
...
@@ -334,8 +334,8 @@ module.exports = (function() {
...
@@ -334,8 +334,8 @@ module.exports = (function() {
options
=
{
where
:
parseInt
(
Number
(
options
)
||
0
,
0
)}
options
=
{
where
:
parseInt
(
Number
(
options
)
||
0
,
0
)}
}
}
}
}
options
options
.
limit
=
1
.
limit
=
1
return
this
.
QueryInterface
.
select
(
this
,
this
.
getTableName
(),
options
,
Utils
.
_
.
defaults
({
return
this
.
QueryInterface
.
select
(
this
,
this
.
getTableName
(),
options
,
Utils
.
_
.
defaults
({
plain
:
true
,
plain
:
true
,
...
@@ -651,6 +651,18 @@ module.exports = (function() {
...
@@ -651,6 +651,18 @@ module.exports = (function() {
delete
include
.
model
delete
include
.
model
}
}
if
(
include
.
hasOwnProperty
(
'attributes'
))
{
var
primaryKeys
;
if
(
include
.
daoFactory
.
hasPrimaryKeys
)
{
primaryKeys
=
include
.
daoFactory
.
primaryKeys
}
else
{
primaryKeys
=
[
'id'
]
}
include
.
attributes
=
include
.
attributes
.
concat
(
primaryKeys
)
}
else
{
include
.
attributes
=
Object
.
keys
(
include
.
daoFactory
.
attributes
)
}
if
(
include
.
hasOwnProperty
(
'daoFactory'
)
&&
(
include
.
hasOwnProperty
(
'as'
)))
{
if
(
include
.
hasOwnProperty
(
'daoFactory'
)
&&
(
include
.
hasOwnProperty
(
'as'
)))
{
var
usesAlias
=
(
include
.
as
!==
include
.
daoFactory
.
tableName
)
var
usesAlias
=
(
include
.
as
!==
include
.
daoFactory
.
tableName
)
,
association
=
(
usesAlias
?
this
.
getAssociationByAlias
(
include
.
as
)
:
this
.
getAssociation
(
include
.
daoFactory
))
,
association
=
(
usesAlias
?
this
.
getAssociationByAlias
(
include
.
as
)
:
this
.
getAssociation
(
include
.
daoFactory
))
...
...
lib/dialects/mysql/query-generator.js
View file @
0ee89ca
...
@@ -181,7 +181,7 @@ module.exports = (function() {
...
@@ -181,7 +181,7 @@ module.exports = (function() {
var
optAttributes
=
options
.
attributes
===
'*'
?
[
options
.
table
+
'.*'
]
:
[
options
.
attributes
]
var
optAttributes
=
options
.
attributes
===
'*'
?
[
options
.
table
+
'.*'
]
:
[
options
.
attributes
]
options
.
include
.
forEach
(
function
(
include
)
{
options
.
include
.
forEach
(
function
(
include
)
{
var
attributes
=
Object
.
keys
(
include
.
daoFactory
.
attributes
)
.
map
(
function
(
attr
)
{
var
attributes
=
include
.
attributes
.
map
(
function
(
attr
)
{
return
this
.
quoteIdentifier
(
include
.
as
)
+
"."
+
this
.
quoteIdentifier
(
attr
)
+
" AS "
+
this
.
quoteIdentifier
(
include
.
as
+
"."
+
attr
)
return
this
.
quoteIdentifier
(
include
.
as
)
+
"."
+
this
.
quoteIdentifier
(
attr
)
+
" AS "
+
this
.
quoteIdentifier
(
include
.
as
+
"."
+
attr
)
}.
bind
(
this
))
}.
bind
(
this
))
...
...
lib/dialects/postgres/query-generator.js
View file @
0ee89ca
...
@@ -252,7 +252,7 @@ module.exports = (function() {
...
@@ -252,7 +252,7 @@ module.exports = (function() {
var
optAttributes
=
options
.
attributes
===
'*'
?
[
options
.
table
+
'.*'
]
:
[
options
.
attributes
]
var
optAttributes
=
options
.
attributes
===
'*'
?
[
options
.
table
+
'.*'
]
:
[
options
.
attributes
]
options
.
include
.
forEach
(
function
(
include
)
{
options
.
include
.
forEach
(
function
(
include
)
{
var
attributes
=
Object
.
keys
(
include
.
daoFactory
.
attributes
)
.
map
(
function
(
attr
)
{
var
attributes
=
include
.
attributes
.
map
(
function
(
attr
)
{
return
this
.
quoteIdentifier
(
include
.
as
)
+
"."
+
this
.
quoteIdentifier
(
attr
)
+
" AS "
+
this
.
quoteIdentifier
(
include
.
as
+
"."
+
attr
,
true
)
return
this
.
quoteIdentifier
(
include
.
as
)
+
"."
+
this
.
quoteIdentifier
(
attr
)
+
" AS "
+
this
.
quoteIdentifier
(
include
.
as
+
"."
+
attr
,
true
)
}.
bind
(
this
))
}.
bind
(
this
))
...
...
lib/dialects/sqlite/query-generator.js
View file @
0ee89ca
...
@@ -163,7 +163,7 @@ module.exports = (function() {
...
@@ -163,7 +163,7 @@ module.exports = (function() {
var
optAttributes
=
options
.
attributes
===
'*'
?
[
options
.
table
+
'.*'
]
:
[
options
.
attributes
]
var
optAttributes
=
options
.
attributes
===
'*'
?
[
options
.
table
+
'.*'
]
:
[
options
.
attributes
]
options
.
include
.
forEach
(
function
(
include
)
{
options
.
include
.
forEach
(
function
(
include
)
{
var
attributes
=
Object
.
keys
(
include
.
daoFactory
.
attributes
)
.
map
(
function
(
attr
)
{
var
attributes
=
include
.
attributes
.
map
(
function
(
attr
)
{
return
this
.
quoteIdentifier
(
include
.
as
)
+
"."
+
this
.
quoteIdentifier
(
attr
)
+
" AS "
+
this
.
quoteIdentifier
(
include
.
as
+
"."
+
attr
)
return
this
.
quoteIdentifier
(
include
.
as
)
+
"."
+
this
.
quoteIdentifier
(
attr
)
+
" AS "
+
this
.
quoteIdentifier
(
include
.
as
+
"."
+
attr
)
}.
bind
(
this
))
}.
bind
(
this
))
...
...
test/dao-factory.test.js
View file @
0ee89ca
...
@@ -1404,6 +1404,36 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -1404,6 +1404,36 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
})
it
(
'returns the selected fields for both the base table and the included table as instance.selectedValues'
,
function
(
done
)
{
var
self
=
this
self
.
Mission
=
self
.
sequelize
.
define
(
'Mission'
,
{
title
:
{
type
:
Sequelize
.
STRING
,
defaultValue
:
'another mission!!'
},
foo
:
{
type
:
Sequelize
.
INTEGER
,
defaultValue
:
4
},
})
self
.
Mission
.
belongsTo
(
self
.
User
)
self
.
User
.
hasMany
(
self
.
Mission
)
self
.
Mission
.
sync
({
force
:
true
}).
success
(
function
()
{
self
.
Mission
.
create
().
success
(
function
(
mission
)
{
self
.
User
.
create
({
username
:
'Brain Picker'
}).
success
(
function
(
user
)
{
mission
.
setUser
(
user
).
success
(
function
()
{
self
.
User
.
find
({
where
:
{
username
:
'Brain Picker'
},
attributes
:
[
'username'
],
include
:
[{
model
:
self
.
Mission
,
as
:
self
.
Mission
.
tableName
,
attributes
:
[
'title'
]}]
}).
success
(
function
(
user
)
{
expect
(
user
.
selectedValues
).
to
.
deep
.
equal
({
username
:
'Brain Picker'
})
expect
(
user
.
missions
[
0
].
selectedValues
).
to
.
deep
.
equal
({
id
:
1
,
title
:
'another mission!!'
})
expect
(
user
.
missions
[
0
].
foo
).
not
.
to
.
exist
done
()
})
})
})
})
})
})
it
(
'always honors ZERO as primary key'
,
function
(
_done
)
{
it
(
'always honors ZERO as primary key'
,
function
(
_done
)
{
var
self
=
this
var
self
=
this
,
permutations
=
[
,
permutations
=
[
...
...
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