我正在使用Express构建应用程序,将Postgres构建为db,将Sequelize构建为ORM。
这是我得到的回复:
{
"user": {
"user_name": "John",
"post": [
{
"id": 1,
"created_at": "2018-04-16T22:52:59.054Z",
"post_titles": [
{
"title_id": 3571
},
{
"title_id": 3570
},
{
"title_id": 3569
}
]
},
],
}
}
如何计算帖子中有多少个标题?
我有4个型号:
User
,hasMany Posts
Post
,有许多Titles
到PostTitles
Title
PostTitle
这是我的疑问:
User.findOne({
where: { id: req.params.id },
attributes: ['id', 'user_name'],
include: [
{ model: Post,
attributes: ['id', 'created_at'],
include: {
model: PostTitles,
attributes: ['title_id']
}
}
]
})
谢谢!
答案 0 :(得分:0)
您可以使用app.directive('myCarousel', function () {
return {
link: function ($scope, $element) {
var next = $element.find('.next');
var prev = $element.find('.prev');
var items = $element.find('.content li');
var counter = 0;
var amount = items.length;
var current = items[0];
$element.addClass('active')
function navigate (direction) {
current.removeClass('current')
counter = counter + direction
if (direction === -1 && counter < 0) {
counter = amount - 1
}
if (direction === 1 && !items[counter]) {
counter = 0
}
current = items[counter]
current.addClass('current')
}
// go to next quote
next.on('click', function (ev) {
navigate(1)
})
// go back to previous quote
prev.on('click', function (ev) {
navigate(-1)
})
navigate(0)
}
}
})
功能。
count