【发布时间】:2015-02-18 00:07:33
【问题描述】:
我是 ORM 新手,不知道如何使用 ORM。 考虑到我有 5 张桌子:
标签、拍卖、用户、user_tag 和auction_tag
我正在使用 SequelizeJS,我怎样才能得到这样的查询?
select A.id, A.title, A.content, A.createdAt, U.id, U.picture, U.name
from Auction A, User U, User U2
where A.userId = U.id and U2.id = x
and exists (select AT.id
from Auction_Tag AT
where AT.auction = A.id
and AT.tag in ( select T.id
from Tag T, User_Tag UT
where U2.id = UT.user
and UT.tag = T.id
)
);
有什么想法吗?谢谢各位
【问题讨论】:
-
我找到了答案。 :
sequelize.query("SELECT * FROMusers", { type: sequelize.QueryTypes.SELECT}) .then(function(users) { // We don't need spread here, since only the results will be returned for select queries }) -
根据您与表的关系,您可以以比使用类似查询更简洁的方式(至少对于 ORM)实现这一点。
标签: javascript node.js postgresql orm sequelize.js