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 f0a3c83c
authored
Jan 04, 2015
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(include): better support for include by association and where
1 parent
a6b169e3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
3 deletions
changelog.md
lib/model.js
test/include.test.js
changelog.md
View file @
f0a3c83
# 2.0.0-rc6
-
[
BUG
]
Fixed issue with including by association reference and where
# 2.0.0-rc5
# 2.0.0-rc5
-
[
BUG
]
Fixed issue with subquery creating
`include.where`
and a paranoid main model.#2749/#2769
-
[
BUG
]
Fixed issue with subquery creating
`include.where`
and a paranoid main model.#2749/#2769
-
UniqueConstraintErrors will now extend from ValidationError making it possible to catch both with
`.catch(ValidationError)`
-
UniqueConstraintErrors will now extend from ValidationError making it possible to catch both with
`.catch(ValidationError)`
...
...
lib/model.js
View file @
f0a3c83
...
@@ -1952,10 +1952,10 @@ module.exports = (function() {
...
@@ -1952,10 +1952,10 @@ module.exports = (function() {
}
}
if
(
include
.
association
&&
!
include
.
_pseudo
&&
!
include
.
model
)
{
if
(
include
.
association
&&
!
include
.
_pseudo
&&
!
include
.
model
)
{
if
(
include
.
association
.
associationType
===
'BelongsTo'
)
{
if
(
include
.
association
.
source
===
this
)
{
include
.
model
=
include
.
association
.
source
;
}
else
{
include
.
model
=
include
.
association
.
target
;
include
.
model
=
include
.
association
.
target
;
}
else
{
include
.
model
=
include
.
association
.
source
;
}
}
}
}
...
...
test/include.test.js
View file @
f0a3c83
...
@@ -54,6 +54,30 @@ describe(Support.getTestDialectTeaser('Include'), function() {
...
@@ -54,6 +54,30 @@ describe(Support.getTestDialectTeaser('Include'), function() {
});
});
});
});
it
(
'should support a belongsTo association reference with a where'
,
function
()
{
var
Company
=
this
.
sequelize
.
define
(
'Company'
,
{
name
:
DataTypes
.
STRING
})
,
User
=
this
.
sequelize
.
define
(
'User'
,
{})
,
Employer
=
User
.
belongsTo
(
Company
,
{
as
:
'Employer'
,
foreignKey
:
'employerId'
});
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Company
.
create
({
name
:
'CyberCorp'
}).
then
(
function
(
company
)
{
return
User
.
create
({
employerId
:
company
.
get
(
'id'
)
});
});
}).
then
(
function
()
{
return
User
.
findOne
({
include
:
[
{
association
:
Employer
,
where
:
{
name
:
'CyberCorp'
}}
]
}).
then
(
function
(
user
)
{
expect
(
user
).
to
.
be
.
ok
;
});
});
});
it
(
'should support a empty hasOne include'
,
function
(
done
)
{
it
(
'should support a empty hasOne include'
,
function
(
done
)
{
var
Company
=
this
.
sequelize
.
define
(
'Company'
,
{})
var
Company
=
this
.
sequelize
.
define
(
'Company'
,
{})
,
Person
=
this
.
sequelize
.
define
(
'Person'
,
{});
,
Person
=
this
.
sequelize
.
define
(
'Person'
,
{});
...
@@ -134,6 +158,37 @@ describe(Support.getTestDialectTeaser('Include'), function() {
...
@@ -134,6 +158,37 @@ describe(Support.getTestDialectTeaser('Include'), function() {
});
});
});
});
it
(
'should support a hasMany association reference with a where condition'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'user'
,
{})
,
Task
=
this
.
sequelize
.
define
(
'task'
,
{
title
:
DataTypes
.
STRING
})
,
Tasks
=
User
.
hasMany
(
Task
);
Task
.
belongsTo
(
User
);
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
User
.
create
().
then
(
function
(
user
)
{
return
Promise
.
join
(
user
.
createTask
({
title
:
'trivial'
}),
user
.
createTask
({
title
:
'pursuit'
})
);
}).
then
(
function
()
{
return
User
.
find
({
include
:
[
{
association
:
Tasks
,
where
:
{
title
:
'trivial'
}}
]
});
}).
then
(
function
(
user
)
{
expect
(
user
).
to
.
be
.
ok
;
expect
(
user
.
tasks
).
to
.
be
.
ok
;
expect
(
user
.
tasks
.
length
).
to
.
equal
(
1
);
});
});
});
it
(
'should support a belongsToMany association reference'
,
function
()
{
it
(
'should support a belongsToMany association reference'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'user'
,
{})
var
User
=
this
.
sequelize
.
define
(
'user'
,
{})
,
Group
=
this
.
sequelize
.
define
(
'group'
,
{})
,
Group
=
this
.
sequelize
.
define
(
'group'
,
{})
...
...
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