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 68acb801
authored
May 24, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(model/attributes): primary key support for source tables for includes, closes #1809
1 parent
c4606736
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
4 deletions
lib/dialects/abstract/query-generator.js
lib/instance.js
test/model/attributes.test.js
lib/dialects/abstract/query-generator.js
View file @
68acb80
...
...
@@ -785,13 +785,18 @@ module.exports = (function() {
}
}
}
else
{
var
primaryKeysLeft
=
association
.
associationType
===
'BelongsTo'
?
association
.
target
.
primaryKeyAttributes
:
include
.
association
.
source
.
primaryKeyAttributes
var
left
=
association
.
associationType
===
'BelongsTo'
?
association
.
target
:
include
.
association
.
source
,
primaryKeysLeft
=
association
.
associationType
===
'BelongsTo'
?
left
.
primaryKeyAttributes
:
left
.
primaryKeyAttributes
,
tableLeft
=
association
.
associationType
===
'BelongsTo'
?
as
:
parentTable
,
attrLeft
=
primaryKeysLeft
[
0
]
,
tableRight
=
association
.
associationType
===
'BelongsTo'
?
parentTable
:
as
,
attrRight
=
association
.
identifier
,
joinOn
;
if
(
left
.
rawAttributes
[
attrLeft
].
field
)
{
attrLeft
=
left
.
rawAttributes
[
attrLeft
].
field
;
}
// Filter statement
// Used by both join and subquery where
joinOn
=
...
...
lib/instance.js
View file @
68acb80
...
...
@@ -506,6 +506,16 @@ module.exports = (function() {
}
else
{
var
identifier
=
self
.
primaryKeyValues
;
if
(
identifier
)
{
for
(
var
attrName
in
identifier
)
{
// Field name mapping
if
(
self
.
Model
.
rawAttributes
[
attrName
].
field
)
{
identifier
[
self
.
Model
.
rawAttributes
[
attrName
].
field
]
=
identifier
[
attrName
];
delete
identifier
[
attrName
];
}
}
}
if
(
identifier
===
null
&&
self
.
__options
.
whereCollection
!==
null
)
{
identifier
=
self
.
__options
.
whereCollection
;
}
...
...
test/model/attributes.test.js
View file @
68acb80
...
...
@@ -85,7 +85,7 @@ describe(Support.getTestDialectTeaser("Model"), function () {
type
:
DataTypes
.
STRING
}
})
])
])
;
});
it
(
'should create, fetch and update with alternative field names from a simple model'
,
function
()
{
...
...
@@ -108,7 +108,9 @@ describe(Support.getTestDialectTeaser("Model"), function () {
});
}).
then
(
function
(
user
)
{
expect
(
user
.
get
(
'name'
)).
to
.
equal
(
'Barfoo'
);
})
}).
on
(
'sql'
,
function
(
sql
)
{
console
.
log
(
sql
);
});
});
it
(
'should work with attributes and where on includes'
,
function
()
{
...
...
@@ -131,6 +133,8 @@ describe(Support.getTestDialectTeaser("Model"), function () {
expect
(
user
.
get
(
'name'
)).
to
.
be
.
ok
;
expect
(
user
.
get
(
'tasks'
)[
0
].
get
(
'title'
)).
to
.
equal
(
'DoDat'
);
});
}).
on
(
'sql'
,
function
(
sql
)
{
console
.
log
(
sql
);
});
});
...
...
@@ -147,7 +151,7 @@ describe(Support.getTestDialectTeaser("Model"), function () {
});
}).
then
(
function
(
user
)
{
expect
(
user
).
to
.
be
.
ok
})
})
;
});
it
(
'should work with bulkCreate and findAll'
,
function
()
{
...
...
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