nodejs爬坑記錄
Sequelize
- include連表時(shí)可以設(shè)置
required
屬性會(huì)進(jìn)行內(nèi)聯(lián)(innerJoin,查詢(xún)結(jié)果左右兩邊都有值才獲取)操作,默認(rèn)添加了where屬性則會(huì)將required設(shè)置為true,注意:required僅和父級(jí)進(jìn)行內(nèi)聯(lián) - ? db.transaction(async t => {xxx...})中的子方法必須都要有await 使其都在同一條線程中呕诉,不然不能在同一個(gè)事務(wù)中提交阶捆,會(huì)出現(xiàn)以下錯(cuò)誤 注意在同一個(gè)事務(wù)中的所有操作都要await 必須在一個(gè)線程 不然不觸發(fā)
commit has been called on this transaction(a0989c57-6b52-4093-87a7-02d5ca7e4b08), you can no longer use it. (The rejected query is attached as the 'sql' property of this error)
targetKey可以用在關(guān)聯(lián)中指定目標(biāo)鍵填渠,默認(rèn)是關(guān)聯(lián)另一張表的主鍵
在hasMany中 可以用sourceKey來(lái)指定源鍵帖烘,默認(rèn)為主鍵
注意:sourceKey必須為數(shù)據(jù)庫(kù)字段名,不能使用生成的駝峰式別名多表查詢(xún)時(shí)防止列名沖突最好是把列放在最外層處理
const teamModels = await UserTeamRelation.findAll({
where: { leaderId: userId },
//include代表在原先的字段基礎(chǔ)上再加一個(gè)字段,exclude表示排除某個(gè)字段
attributes: {include:[[Sequelize.fn("SUM", Sequelize.col("userIntegral.integral")), "userIntegral.integral"]]},
include: [{ model: UserIntegralModule, where: { userId }, as: "userIntegral" }
, { model: User, as: "member" }]
});