gpt4 book ai didi

mysql - 为什么在 where 查询中引用其他表的列不起作用?

转载 作者:行者123 更新时间:2023-11-29 16:29:18 25 4
gpt4 key购买 nike

假设我有这个数据库标准对象-

let criteria = {
limit: limit,
offset: offset,
include: [

{
model: Comments,
include: [
{
model: User.scope('public')
},
{
model: Likes
}
]
},
{
model: User.scope('public')
},
{
model: AdOptions,
},
{
model: Images,
},
{
model: Questions,
},
{
model: Likes,
},
{
model: Videos
},
{
model: Tags
}
] ,

/*
* Get only those posts which are from user's friends, public, self created or ads
*/
where: {
[op.or]: [
{
UserId: friendIds
},
{
AdOptionId: { [op.ne]: null}
},
{
public: { [op.eq]: true},
'$Tags.id$': TagsIdsArray
}
]}
};

我这样使用它 -

Posts.findAll(criteria)

。.

我收到以下错误-

{"name":"SequelizeDatabaseError","parent":{"code":"ER_BAD_FIELD_ERROR","errno":1054,"sqlState":"42S22","sqlMessage":"Unknown column 'Tags.id' in 'where clause'","sql":"SELECT `Posts`.*, `Comments`.`id` AS `Comments.id`, `Comments`.`type` AS `Comments.type`, `Comments`.`comment` AS `Comments.comment`, `Comments`.`createdAt` AS `Comments.createdAt`, `Comments`.`updatedAt` AS `Comments.updatedAt`, `Comments`.`PostId` AS `Comments.PostId`, `Comments`.`UserId` AS `Comments.UserId`, `Comments->PostComments`.`createdAt` AS `Comments.PostComments.createdAt`, `Comments->PostComments`.`updatedAt` AS `Comments.PostComments.updatedAt`, `Comments->PostComments`.`PostId` AS `Comments.PostComments.PostId`, `Comments->PostComments`.`CommentId` AS `Comments.PostComments.CommentId`, `Comments->User`.`id` AS `Comments.User.id`, `Comments->User`.`first` AS `Comments.User.first`, `Comments->User`.`last` AS `Comments.User.last`, `Comments->User`.`phone` AS `Comments.User.phone`, `Comments->User`.`pic` AS `Comments.User.pic`, `Comments->Likes`.`id` AS `Comments.Likes.id`, `Comments->Likes`.`createdAt` AS `Comments.Likes.createdAt`, `Comments->Likes`.`updatedAt` AS `Comments.Likes.updatedAt`, `Comments->Likes`.`UserId` AS `Comments.Likes.UserId`, `Comments->Likes`.`PostId` AS `Comments.Likes.PostId`, `Comments->Likes`.`CommentId` AS `Comments.Likes.CommentId`, `Comments->Likes->CommentLikes`.`createdAt` AS `Comments.Likes.CommentLikes.createdAt`, `Comments->Likes->CommentLikes`.`updatedAt` AS `Comments.Likes.CommentLikes.updatedAt`, `Comments->Likes->CommentLikes`.`CommentId` AS `Comments.Likes.CommentLikes.CommentId`, `Comments->Likes->CommentLikes`.`LikeId` AS `Comments.Likes.CommentLikes.LikeId`, `User`.`id` AS `User.id`, `User`.`first` AS `User.first`, `User`.`last` AS `User.last`, `User`.`phone` AS `User.phone`, `User`.`pic` AS `User.pic`, `AdOption`.`id` AS `AdOption.id`, `AdOption`.`postIsAd` AS `AdOption.postIsAd`, `AdOption`.`cpc` AS `AdOption.cpc`, `AdOption`.`cpv` AS `AdOption.cpv`, `AdOption`.`clickURL` AS `AdOption.clickURL`, `AdOption`.`createdAt` AS `AdOption.createdAt`, `AdOption`.`updatedAt` AS `AdOption.updatedAt`, `AdOption`.`UserId` AS `AdOption.UserId`, `Images`.`id` AS `Images.id`, `Images`.`path` AS `Images.path`, `Images`.`createdAt` AS `Images.createdAt`, `Images`.`updatedAt` AS `Images.updatedAt`, `Images`.`UserId` AS `Images.UserId`, `Images`.`PostId` AS `Images.PostId`, `Images->PostImages`.`createdAt` AS `Images.PostImages.createdAt`, `Images->PostImages`.`updatedAt` AS `Images.PostImages.updatedAt`, `Images->PostImages`.`PostId` AS `Images.PostImages.PostId`, `Images->PostImages`.`ImageId` AS `Images.PostImages.ImageId`, `Question`.`id` AS `Question.id`, `Question`.`question` AS `Question.question`, `Question`.`description` AS `Question.description`, `Question`.`createdAt` AS `Question.createdAt`, `Question`.`updatedAt` AS `Question.updatedAt`, `Question`.`UserId` AS `Question.UserId`, `Likes`.`id` AS `Likes.id`, `Likes`.`createdAt` AS `Likes.createdAt`, `Likes`.`updatedAt` AS `Likes.updatedAt`, `Likes`.`UserId` AS `Likes.UserId`, `Likes`.`PostId` AS `Likes.PostId`, `Likes`.`CommentId` AS `Likes.CommentId`, `Likes->PostLikes`.`createdAt` AS `Likes.PostLikes.createdAt`, `Likes->PostLikes`.`updatedAt` AS `Likes.PostLikes.updatedAt`, `Likes->PostLikes`.`PostId` AS `Likes.PostLikes.PostId`, `Likes->PostLikes`.`LikeId` AS `Likes.PostLikes.LikeId`, `Video`.`id` AS `Video.id`, `Video`.`title` AS `Video.title`, `Video`.`description` AS `Video.description`, `Video`.`path` AS `Video.path`, `Video`.`createdAt` AS `Video.createdAt`, `Video`.`updatedAt` AS `Video.updatedAt`, `Video`.`UserId` AS `Video.UserId`, `Tags`.`id` AS `Tags.id`, `Tags`.`name` AS `Tags.name`, `Tags`.`icon` AS `Tags.icon`, `Tags`.`UserId` AS `Tags.UserId`, `Tags`.`createdAt` AS `Tags.createdAt`, `Tags`.`updatedAt` AS `Tags.updatedAt`, `Tags->PostsTags`.`createdAt` AS `Tags.PostsTags.createdAt`, `Tags->PostsTags`.`updatedAt` AS `Tags.PostsTags.updatedAt`, `Tags->PostsTags`.`PostId` AS `Tags.PostsTags.PostId`, `Tags->PostsTags`.`TagId` AS `Tags.PostsTags.TagId` FROM (SELECT `Posts`.`id`, `Posts`.`type`, `Posts`.`content`, `Posts`.`public`, `Posts`.`createdAt`, `Posts`.`updatedAt`, `Posts`.`UserId`, `Posts`.`QuestionId`, `Posts`.`AdOptionId`, `Posts`.`VideoId` FROM `Posts` AS `Posts` WHERE (`Posts`.`UserId` IN (1) OR `Posts`.`AdOptionId` IS NOT NULL OR (`Posts`.`public` = true AND `Tags`.`id` IN (1))) ORDER BY `Posts`.`updatedAt` DESC LIMIT 0, 10) AS `Posts` LEFT OUTER JOIN ( `PostComments` AS `Comments->PostComments` INNER JOIN `Comments` AS `Comments` ON `Comments`.`id` = `Comments->PostComments`.`CommentId`) ON `Posts`.`id` = `Comments->PostComments`.`PostId` LEFT OUTER JOIN `Users` AS `Comments->User` ON `Comments`.`UserId` = `Comments->User`.`id` LEFT OUTER JOIN ( `CommentLikes` AS `Comments->Likes->CommentLikes` INNER JOIN `Likes` AS `Comments->Likes` ON `Comments->Likes`.`id` = `Comments->Likes->CommentLikes`.`LikeId`) ON `Comments`.`id` = `Comments->Likes->CommentLikes`.`CommentId` LEFT OUTER JOIN `Users` AS `User` ON `Posts`.`UserId` = `User`.`id` LEFT OUTER JOIN `AdOptions` AS `AdOption` ON `Posts`.`AdOptionId` = `AdOption`.`id` LEFT OUTER JOIN ( `PostImages` AS `Images->PostImages` INNER JOIN `Images` AS `Images` ON `Images`.`id` = `Images->PostImages`.`ImageId`) ON `Posts`.`id` = `Images->PostImages`.`PostId` LEFT OUTER JOIN `Questions` AS `Question` ON `Posts`.`QuestionId` = `Question`.`id` LEFT OUTER JOIN ( `PostLikes` AS `Likes->PostLikes` INNER JOIN `Likes` AS `Likes` ON `Likes`.`id` = `Likes->PostLikes`.`LikeId`) ON `Posts`.`id` = `Likes->PostLikes`.`PostId` LEFT OUTER JOIN `Videos` AS `Video` ON `Posts`.`VideoId` = `Video`.`id` LEFT OUTER JOIN ( `PostsTags` AS `Tags->PostsTags` INNER JOIN `Tags` AS `Tags` ON `Tags`.`id` = `Tags->PostsTags`.`TagId`) ON `Posts`.`id` = `Tags->PostsTags`.`PostId` ORDER BY `Posts`.`updatedAt` DESC;"},"original":{"code":"ER_BAD_FIELD_ERROR","errno":1054,"sqlState":"42S22","sqlMessage":"Unknown column 'Tags.id' in 'where clause'","sql":"SELECT `Posts`.*, `Comments`.`id` AS `Comments.id`, `Comments`.`type` AS `Comments.type`, `Comments`.`comment` AS `Comments.comment`, `Comments`.`createdAt` AS `Comments.createdAt`, `Comments`.`updatedAt` AS `Comments.updatedAt`, `Comments`.`PostId` AS `Comments.PostId`, `Comments`.`UserId` AS `Comments.UserId`, `Comments->PostComments`.`createdAt` AS `Comments.PostComments.createdAt`, `Comments->PostComments`.`updatedAt` AS `Comments.PostComments.updatedAt`, `Comments->PostComments`.`PostId` AS `Comments.PostComments.PostId`, `Comments->PostComments`.`CommentId` AS `Comments.PostComments.CommentId`, `Comments->User`.`id` AS `Comments.User.id`, `Comments->User`.`first` AS `Comments.User.first`, `Comments->User`.`last` AS `Comments.User.last`, `Comments->User`.`phone` AS `Comments.User.phone`, `Comments->User`.`pic` AS `Comments.User.pic`, `Comments->Likes`.`id` AS `Comments.Likes.id`, `Comments->Likes`.`createdAt` AS `Comments.Likes.createdAt`, `Comments->Likes`.`updatedAt` AS `Comments.Likes.updatedAt`, `Comments->Likes`.`UserId` AS `Comments.Likes.UserId`, `Comments->Likes`.`PostId` AS `Comments.Likes.PostId`, `Comments->Likes`.`CommentId` AS `Comments.Likes.CommentId`, `Comments->Likes->CommentLikes`.`createdAt` AS `Comments.Likes.CommentLikes.createdAt`, `Comments->Likes->CommentLikes`.`updatedAt` AS `Comments.Likes.CommentLikes.updatedAt`, `Comments->Likes->CommentLikes`.`CommentId` AS `Comments.Likes.CommentLikes.CommentId`, `Comments->Likes->CommentLikes`.`LikeId` AS `Comments.Likes.CommentLikes.LikeId`, `User`.`id` AS `User.id`, `User`.`first` AS `User.first`, `User`.`last` AS `User.last`, `User`.`phone` AS `User.phone`, `User`.`pic` AS `User.pic`, `AdOption`.`id` AS `AdOption.id`, `AdOption`.`postIsAd` AS `AdOption.postIsAd`, `AdOption`.`cpc` AS `AdOption.cpc`, `AdOption`.`cpv` AS `AdOption.cpv`, `AdOption`.`clickURL` AS `AdOption.clickURL`, `AdOption`.`createdAt` AS `AdOption.createdAt`, `AdOption`.`updatedAt` AS `AdOption.updatedAt`, `AdOption`.`UserId` AS `AdOption.UserId`, `Images`.`id` AS `Images.id`, `Images`.`path` AS `Images.path`, `Images`.`createdAt` AS `Images.createdAt`, `Images`.`updatedAt` AS `Images.updatedAt`, `Images`.`UserId` AS `Images.UserId`, `Images`.`PostId` AS `Images.PostId`, `Images->PostImages`.`createdAt` AS `Images.PostImages.createdAt`, `Images->PostImages`.`updatedAt` AS `Images.PostImages.updatedAt`, `Images->PostImages`.`PostId` AS `Images.PostImages.PostId`, `Images->PostImages`.`ImageId` AS `Images.PostImages.ImageId`, `Question`.`id` AS `Question.id`, `Question`.`question` AS `Question.question`, `Question`.`description` AS `Question.description`, `Question`.`createdAt` AS `Question.createdAt`, `Question`.`updatedAt` AS `Question.updatedAt`, `Question`.`UserId` AS `Question.UserId`, `Likes`.`id` AS `Likes.id`, `Likes`.`createdAt` AS `Likes.createdAt`, `Likes`.`updatedAt` AS `Likes.updatedAt`, `Likes`.`UserId` AS `Likes.UserId`, `Likes`.`PostId` AS `Likes.PostId`, `Likes`.`CommentId` AS `Likes.CommentId`, `Likes->PostLikes`.`createdAt` AS `Likes.PostLikes.createdAt`, `Likes->PostLikes`.`updatedAt` AS `Likes.PostLikes.updatedAt`, `Likes->PostLikes`.`PostId` AS `Likes.PostLikes.PostId`, `Likes->PostLikes`.`LikeId` AS `Likes.PostLikes.LikeId`, `Video`.`id` AS `Video.id`, `Video`.`title` AS `Video.title`, `Video`.`description` AS `Video.description`, `Video`.`path` AS `Video.path`, `Video`.`createdAt` AS `Video.createdAt`, `Video`.`updatedAt` AS `Video.updatedAt`, `Video`.`UserId` AS `Video.UserId`, `Tags`.`id` AS `Tags.id`, `Tags`.`name` AS `Tags.name`, `Tags`.`icon` AS `Tags.icon`, `Tags`.`UserId` AS `Tags.UserId`, `Tags`.`createdAt` AS `Tags.createdAt`, `Tags`.`updatedAt` AS `Tags.updatedAt`, `Tags->PostsTags`.`createdAt` AS `Tags.PostsTags.createdAt`, `Tags->PostsTags`.`updatedAt` AS `Tags.PostsTags.updatedAt`, `Tags->PostsTags`.`PostId` AS `Tags.PostsTags.PostId`, `Tags->PostsTags`.`TagId` AS `Tags.PostsTags.TagId` FROM (SELECT `Posts`.`id`, `Posts`.`type`, `Posts`.`content`, `Posts`.`public`, `Posts`.`createdAt`, `Posts`.`updatedAt`, `Posts`.`UserId`, `Posts`.`QuestionId`, `Posts`.`AdOptionId`, `Posts`.`VideoId` FROM `Posts` AS `Posts` WHERE (`Posts`.`UserId` IN (1) OR `Posts`.`AdOptionId` IS NOT NULL OR (`Posts`.`public` = true AND `Tags`.`id` IN (1))) ORDER BY `Posts`.`updatedAt` DESC LIMIT 0, 10) AS `Posts` LEFT OUTER JOIN ( `PostComments` AS `Comments->PostComments` INNER JOIN `Comments` AS `Comments` ON `Comments`.`id` = `Comments->PostComments`.`CommentId`) ON `Posts`.`id` = `Comments->PostComments`.`PostId` LEFT OUTER JOIN `Users` AS `Comments->User` ON `Comments`.`UserId` = `Comments->User`.`id` LEFT OUTER JOIN ( `CommentLikes` AS `Comments->Likes->CommentLikes` INNER JOIN `Likes` AS `Comments->Likes` ON `Comments->Likes`.`id` = `Comments->Likes->CommentLikes`.`LikeId`) ON `Comments`.`id` = `Comments->Likes->CommentLikes`.`CommentId` LEFT OUTER JOIN `Users` AS `User` ON `Posts`.`UserId` = `User`.`id` LEFT OUTER JOIN `AdOptions` AS `AdOption` ON `Posts`.`AdOptionId` = `AdOption`.`id` LEFT OUTER JOIN ( `PostImages` AS `Images->PostImages` INNER JOIN `Images` AS `Images` ON `Images`.`id` = `Images->PostImages`.`ImageId`) ON `Posts`.`id` = `Images->PostImages`.`PostId` LEFT OUTER JOIN `Questions` AS `Question` ON `Posts`.`QuestionId` = `Question`.`id` LEFT OUTER JOIN ( `PostLikes` AS `Likes->PostLikes` INNER JOIN `Likes` AS `Likes` ON `Likes`.`id` = `Likes->PostLikes`.`LikeId`) ON `Posts`.`id` = `Likes->PostLikes`.`PostId` LEFT OUTER JOIN `Videos` AS `Video` ON `Posts`.`VideoId` = `Video`.`id` LEFT OUTER JOIN ( `PostsTags` AS `Tags->PostsTags` INNER JOIN `Tags` AS `Tags` ON `Tags`.`id` = `Tags->PostsTags`.`TagId`) ON `Posts`.`id` = `Tags->PostsTags`.`PostId` ORDER BY `Posts`.`updatedAt` DESC;"},"sql":"SELECT `Posts`.*, `Comments`.`id` AS `Comments.id`, `Comments`.`type` AS `Comments.type`, `Comments`.`comment` AS `Comments.comment`, `Comments`.`createdAt` AS `Comments.createdAt`, `Comments`.`updatedAt` AS `Comments.updatedAt`, `Comments`.`PostId` AS `Comments.PostId`, `Comments`.`UserId` AS `Comments.UserId`, `Comments->PostComments`.`createdAt` AS `Comments.PostComments.createdAt`, `Comments->PostComments`.`updatedAt` AS `Comments.PostComments.updatedAt`, `Comments->PostComments`.`PostId` AS `Comments.PostComments.PostId`, `Comments->PostComments`.`CommentId` AS `Comments.PostComments.CommentId`, `Comments->User`.`id` AS `Comments.User.id`, `Comments->User`.`first` AS `Comments.User.first`, `Comments->User`.`last` AS `Comments.User.last`, `Comments->User`.`phone` AS `Comments.User.phone`, `Comments->User`.`pic` AS `Comments.User.pic`, `Comments->Likes`.`id` AS `Comments.Likes.id`, `Comments->Likes`.`createdAt` AS `Comments.Likes.createdAt`, `Comments->Likes`.`updatedAt` AS `Comments.Likes.updatedAt`, `Comments->Likes`.`UserId` AS `Comments.Likes.UserId`, `Comments->Likes`.`PostId` AS `Comments.Likes.PostId`, `Comments->Likes`.`CommentId` AS `Comments.Likes.CommentId`, `Comments->Likes->CommentLikes`.`createdAt` AS `Comments.Likes.CommentLikes.createdAt`, `Comments->Likes->CommentLikes`.`updatedAt` AS `Comments.Likes.CommentLikes.updatedAt`, `Comments->Likes->CommentLikes`.`CommentId` AS `Comments.Likes.CommentLikes.CommentId`, `Comments->Likes->CommentLikes`.`LikeId` AS `Comments.Likes.CommentLikes.LikeId`, `User`.`id` AS `User.id`, `User`.`first` AS `User.first`, `User`.`last` AS `User.last`, `User`.`phone` AS `User.phone`, `User`.`pic` AS `User.pic`, `AdOption`.`id` AS `AdOption.id`, `AdOption`.`postIsAd` AS `AdOption.postIsAd`, `AdOption`.`cpc` AS `AdOption.cpc`, `AdOption`.`cpv` AS `AdOption.cpv`, `AdOption`.`clickURL` AS `AdOption.clickURL`, `AdOption`.`createdAt` AS `AdOption.createdAt`, `AdOption`.`updatedAt` AS `AdOption.updatedAt`, `AdOption`.`UserId` AS `AdOption.UserId`, `Images`.`id` AS `Images.id`, `Images`.`path` AS `Images.path`, `Images`.`createdAt` AS `Images.createdAt`, `Images`.`updatedAt` AS `Images.updatedAt`, `Images`.`UserId` AS `Images.UserId`, `Images`.`PostId` AS `Images.PostId`, `Images->PostImages`.`createdAt` AS `Images.PostImages.createdAt`, `Images->PostImages`.`updatedAt` AS `Images.PostImages.updatedAt`, `Images->PostImages`.`PostId` AS `Images.PostImages.PostId`, `Images->PostImages`.`ImageId` AS `Images.PostImages.ImageId`, `Question`.`id` AS `Question.id`, `Question`.`question` AS `Question.question`, `Question`.`description` AS `Question.description`, `Question`.`createdAt` AS `Question.createdAt`, `Question`.`updatedAt` AS `Question.updatedAt`, `Question`.`UserId` AS `Question.UserId`, `Likes`.`id` AS `Likes.id`, `Likes`.`createdAt` AS `Likes.createdAt`, `Likes`.`updatedAt` AS `Likes.updatedAt`, `Likes`.`UserId` AS `Likes.UserId`, `Likes`.`PostId` AS `Likes.PostId`, `Likes`.`CommentId` AS `Likes.CommentId`, `Likes->PostLikes`.`createdAt` AS `Likes.PostLikes.createdAt`, `Likes->PostLikes`.`updatedAt` AS `Likes.PostLikes.updatedAt`, `Likes->PostLikes`.`PostId` AS `Likes.PostLikes.PostId`, `Likes->PostLikes`.`LikeId` AS `Likes.PostLikes.LikeId`, `Video`.`id` AS `Video.id`, `Video`.`title` AS `Video.title`, `Video`.`description` AS `Video.description`, `Video`.`path` AS `Video.path`, `Video`.`createdAt` AS `Video.createdAt`, `Video`.`updatedAt` AS `Video.updatedAt`, `Video`.`UserId` AS `Video.UserId`, `Tags`.`id` AS `Tags.id`, `Tags`.`name` AS `Tags.name`, `Tags`.`icon` AS `Tags.icon`, `Tags`.`UserId` AS `Tags.UserId`, `Tags`.`createdAt` AS `Tags.createdAt`, `Tags`.`updatedAt` AS `Tags.updatedAt`, `Tags->PostsTags`.`createdAt` AS `Tags.PostsTags.createdAt`, `Tags->PostsTags`.`updatedAt` AS `Tags.PostsTags.updatedAt`, `Tags->PostsTags`.`PostId` AS `Tags.PostsTags.PostId`, `Tags->PostsTags`.`TagId` AS `Tags.PostsTags.TagId` FROM (SELECT `Posts`.`id`, `Posts`.`type`, `Posts`.`content`, `Posts`.`public`, `Posts`.`createdAt`, `Posts`.`updatedAt`, `Posts`.`UserId`, `Posts`.`QuestionId`, `Posts`.`AdOptionId`, `Posts`.`VideoId` FROM `Posts` AS `Posts` WHERE (`Posts`.`UserId` IN (1) OR `Posts`.`AdOptionId` IS NOT NULL OR (`Posts`.`public` = true AND `Tags`.`id` IN (1))) ORDER BY `Posts`.`updatedAt` DESC LIMIT 0, 10) AS `Posts` LEFT OUTER JOIN ( `PostComments` AS `Comments->PostComments` INNER JOIN `Comments` AS `Comments` ON `Comments`.`id` = `Comments->PostComments`.`CommentId`) ON `Posts`.`id` = `Comments->PostComments`.`PostId` LEFT OUTER JOIN `Users` AS `Comments->User` ON `Comments`.`UserId` = `Comments->User`.`id` LEFT OUTER JOIN ( `CommentLikes` AS `Comments->Likes->CommentLikes` INNER JOIN `Likes` AS `Comments->Likes` ON `Comments->Likes`.`id` = `Comments->Likes->CommentLikes`.`LikeId`) ON `Comments`.`id` = `Comments->Likes->CommentLikes`.`CommentId` LEFT OUTER JOIN `Users` AS `User` ON `Posts`.`UserId` = `User`.`id` LEFT OUTER JOIN `AdOptions` AS `AdOption` ON `Posts`.`AdOptionId` = `AdOption`.`id` LEFT OUTER JOIN ( `PostImages` AS `Images->PostImages` INNER JOIN `Images` AS `Images` ON `Images`.`id` = `Images->PostImages`.`ImageId`) ON `Posts`.`id` = `Images->PostImages`.`PostId` LEFT OUTER JOIN `Questions` AS `Question` ON `Posts`.`QuestionId` = `Question`.`id` LEFT OUTER JOIN ( `PostLikes` AS `Likes->PostLikes` INNER JOIN `Likes` AS `Likes` ON `Likes`.`id` = `Likes->PostLikes`.`LikeId`) ON `Posts`.`id` = `Likes->PostLikes`.`PostId` LEFT OUTER JOIN `Videos` AS `Video` ON `Posts`.`VideoId` = `Video`.`id` LEFT OUTER JOIN ( `PostsTags` AS `Tags->PostsTags` INNER JOIN `Tags` AS `Tags` ON `Tags`.`id` = `Tags->PostsTags`.`TagId`) ON `Posts`.`id` = `Tags->PostsTags`.`PostId` ORDER BY `Posts`.`updatedAt` DESC;","success":true}

为什么我收到错误“where 子句”中的未知列“Tags.id”?

请帮忙。我希望我已经提供了足够的信息,如果没有,请告诉我您是否还想了解其他信息?谢谢!

最佳答案

我解决了这个问题。我发现在父级的 where 子句中引用子模型/表的列会破坏查询,因为父模型中使用了限制和偏移参数(很抱歉没有在原始问题中发布限制和偏移代码片段,我编辑了问题并添加了现在)。

所以我发现了一种巧妙的方法,通过调整 ORDER 参数并在其中包含限制和偏移量。

因此,从父级中删除 Limit 和 Offset 参数并将 ORDER 参数更改为此解决了我的问题-

order: Sequelize.literal('updatedAt DESC LIMIT '+ offset + ',' + limit), 

关于mysql - 为什么在 where 查询中引用其他表的列不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54034619/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com