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 67e2a5b9
authored
Jan 11, 2016
by
Matt Liszewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clear out options.groupedLimit if no limit is passed on nested include
1 parent
84274122
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
0 deletions
lib/associations/has-many.js
test/integration/associations/has-many.test.js
lib/associations/has-many.js
View file @
67e2a5b
...
@@ -295,6 +295,7 @@ HasMany.prototype.get = function(instances, options) {
...
@@ -295,6 +295,7 @@ HasMany.prototype.get = function(instances, options) {
where
[
association
.
foreignKey
]
=
{
where
[
association
.
foreignKey
]
=
{
$in
:
values
$in
:
values
};
};
delete
options
.
groupedLimit
;
}
}
}
else
{
}
else
{
where
[
association
.
foreignKey
]
=
instance
.
get
(
association
.
source
.
primaryKeyAttribute
,
{
raw
:
true
});
where
[
association
.
foreignKey
]
=
instance
.
get
(
association
.
source
.
primaryKeyAttribute
,
{
raw
:
true
});
...
...
test/integration/associations/has-many.test.js
View file @
67e2a5b
...
@@ -116,6 +116,100 @@ describe(Support.getTestDialectTeaser('HasMany'), function() {
...
@@ -116,6 +116,100 @@ describe(Support.getTestDialectTeaser('HasMany'), function() {
});
});
});
});
it
(
'should fetch multiple layers of associations with limit and order with separate=true'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
DataTypes
.
STRING
})
,
SubTask
=
this
.
sequelize
.
define
(
'SubTask'
,
{
title
:
DataTypes
.
STRING
});
User
.
Tasks
=
User
.
hasMany
(
Task
,
{
as
:
'tasks'
});
Task
.
SubTasks
=
Task
.
hasMany
(
SubTask
,
{
as
:
'subtasks'
});
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Promise
.
join
(
User
.
create
({
tasks
:
[
{
title
:
'b'
,
subtasks
:
[
{
title
:
'c'
},
{
title
:
'a'
}
]},
{
title
:
'd'
},
{
title
:
'c'
,
subtasks
:
[
{
title
:
'b'
},
{
title
:
'a'
},
{
title
:
'c'
}
]},
{
title
:
'a'
,
subtasks
:
[
{
title
:
'c'
},
{
title
:
'a'
},
{
title
:
'b'
}
]}
]
},
{
include
:
[{
association
:
User
.
Tasks
,
include
:
[
Task
.
SubTasks
]}]
}),
User
.
create
({
tasks
:
[
{
title
:
'a'
,
subtasks
:
[
{
title
:
'b'
},
{
title
:
'a'
},
{
title
:
'c'
}
]},
{
title
:
'c'
,
subtasks
:
[
{
title
:
'a'
}
]},
{
title
:
'b'
,
subtasks
:
[
{
title
:
'a'
},
{
title
:
'b'
}
]}
]
},
{
include
:
[{
association
:
User
.
Tasks
,
include
:
[
Task
.
SubTasks
]}]
})
);
}).
then
(
function
(
users
)
{
return
User
.
findAll
(
{
include
:
[{
association
:
User
.
Tasks
,
limit
:
2
,
order
:
[[
'title'
,
'ASC'
]],
separate
:
true
,
as
:
'tasks'
,
include
:
[{
association
:
Task
.
SubTasks
,
order
:
[[
'title'
,
'DESC'
]],
separate
:
true
,
as
:
'subtasks'
}]
}]
}).
then
(
function
(
users
)
{
expect
(
users
[
0
].
tasks
.
length
).
to
.
equal
(
2
);
expect
(
users
[
0
].
tasks
[
0
].
title
).
to
.
equal
(
'a'
);
expect
(
users
[
0
].
tasks
[
0
].
subtasks
.
length
).
to
.
equal
(
3
);
expect
(
users
[
0
].
tasks
[
0
].
subtasks
[
0
].
title
).
to
.
equal
(
'c'
);
expect
(
users
[
0
].
tasks
[
0
].
subtasks
[
1
].
title
).
to
.
equal
(
'b'
);
expect
(
users
[
0
].
tasks
[
0
].
subtasks
[
2
].
title
).
to
.
equal
(
'a'
);
expect
(
users
[
0
].
tasks
[
1
].
title
).
to
.
equal
(
'b'
);
expect
(
users
[
0
].
tasks
[
1
].
subtasks
.
length
).
to
.
equal
(
2
);
expect
(
users
[
0
].
tasks
[
1
].
subtasks
[
0
].
title
).
to
.
equal
(
'c'
);
expect
(
users
[
0
].
tasks
[
1
].
subtasks
[
1
].
title
).
to
.
equal
(
'a'
);
expect
(
users
[
1
].
tasks
.
length
).
to
.
equal
(
2
);
expect
(
users
[
1
].
tasks
[
0
].
title
).
to
.
equal
(
'a'
);
expect
(
users
[
1
].
tasks
[
0
].
subtasks
.
length
).
to
.
equal
(
3
);
expect
(
users
[
1
].
tasks
[
0
].
subtasks
[
0
].
title
).
to
.
equal
(
'c'
);
expect
(
users
[
1
].
tasks
[
0
].
subtasks
[
1
].
title
).
to
.
equal
(
'b'
);
expect
(
users
[
1
].
tasks
[
0
].
subtasks
[
2
].
title
).
to
.
equal
(
'a'
);
expect
(
users
[
1
].
tasks
[
1
].
title
).
to
.
equal
(
'b'
);
expect
(
users
[
1
].
tasks
[
1
].
subtasks
.
length
).
to
.
equal
(
2
);
expect
(
users
[
1
].
tasks
[
1
].
subtasks
[
0
].
title
).
to
.
equal
(
'b'
);
expect
(
users
[
1
].
tasks
[
1
].
subtasks
[
1
].
title
).
to
.
equal
(
'a'
);
});
});
});
it
(
'should fetch associations for multiple instances with limit and order and a belongsTo relation'
,
function
()
{
it
(
'should fetch associations for multiple instances with limit and order and a belongsTo relation'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
...
...
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