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 abf50093
authored
Aug 23, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'janmeier-eagerloadedAttributes'
2 parents
d0f23946
75a695b7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
5 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 @
abf5009
...
...
@@ -169,7 +169,7 @@ module.exports = (function() {
this
.
DAO
.
prototype
.
__factory
=
this
this
.
DAO
.
prototype
.
hasDefaultValues
=
!
Utils
.
_
.
isEmpty
(
this
.
DAO
.
prototype
.
defaultValues
)
return
this
}
...
...
@@ -334,7 +334,7 @@ module.exports = (function() {
options
=
{
where
:
parseInt
(
Number
(
options
)
||
0
,
0
)}
}
}
options
.
limit
=
1
return
this
.
QueryInterface
.
select
(
this
,
this
.
getTableName
(),
options
,
Utils
.
_
.
defaults
({
...
...
@@ -646,6 +646,18 @@ module.exports = (function() {
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'
)))
{
var
usesAlias
=
(
include
.
as
!==
include
.
daoFactory
.
tableName
)
,
association
=
(
usesAlias
?
this
.
getAssociationByAlias
(
include
.
as
)
:
this
.
getAssociation
(
include
.
daoFactory
))
...
...
lib/dialects/mysql/query-generator.js
View file @
abf5009
...
...
@@ -182,7 +182,7 @@ module.exports = (function() {
var
optAttributes
=
options
.
attributes
===
'*'
?
[
options
.
table
+
'.*'
]
:
[
options
.
attributes
]
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
)
}.
bind
(
this
))
...
...
lib/dialects/postgres/query-generator.js
View file @
abf5009
...
...
@@ -253,7 +253,7 @@ module.exports = (function() {
var
optAttributes
=
options
.
attributes
===
'*'
?
[
options
.
table
+
'.*'
]
:
[
options
.
attributes
]
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
)
}.
bind
(
this
))
...
...
lib/dialects/sqlite/query-generator.js
View file @
abf5009
...
...
@@ -164,7 +164,7 @@ module.exports = (function() {
var
optAttributes
=
options
.
attributes
===
'*'
?
[
options
.
table
+
'.*'
]
:
[
options
.
attributes
]
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
)
}.
bind
(
this
))
...
...
test/dao-factory.test.js
View file @
abf5009
...
...
@@ -1471,6 +1471,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
)
{
var
self
=
this
,
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