小编Sim*_*lam的帖子

询问续集中的关联在哪里?

where子句用于内部连接中的sequelize.我的疑问是

SELECT Cou.country_id,cou.country_name, Sta.state_id, Sta.state_name
FROM hp_country Cou
INNER JOIN hp_state Sta ON Cou.country_id = Sta.hp_country_id
WHERE (Cou.country_status=1 AND Sta.state_status=1 AND Cou.country_id=1)
AND (Sta.state_name LIKE '%ta%');
Run Code Online (Sandbox Code Playgroud)

我在续集代码中写的是

hp_country.findAll({
    where: {
        '$hp_state.state_status$': 1
    },
    include: [
        {model: hp_state}
    ]
})
Run Code Online (Sandbox Code Playgroud)

它产生的错误是:

SELECT `hp_country`.`country_id`, `hp_country`.`country_name`, `hp_country`.`country_status`, `hp_country`.`created_date`, `hp_country`.`update_date` FROM `hp_country` AS `hp_country` WHERE `hp_state`.`state_status` = 1;
Unhandled rejection SequelizeDatabaseError: ER_BAD_FIELD_ERROR: Unknown column 'hp_state.state_status' in 'where clause'
Run Code Online (Sandbox Code Playgroud)

javascript node.js sequelize.js

9
推荐指数
2
解决办法
1万
查看次数

在续集的“where”子句中使用连接表中的列?

我想在续集模型中执行此查询:

SELECT Cou.country_id,cou.country_name, Sta.state_id, Sta.state_name, Dis.district_id,
Dis.district_name,Cit.city_id, Cit.city_name,Loc.location_id,Loc.location_name,Sub_Loc.sub_location_id,Sub_Loc.sub_location_name,Prop.property_id,Prop.property_name,Prop.hp_builders_id,
Bud.builders_id,Bud.builders_name
FROM hp_country Cou
INNER JOIN hp_state Sta ON Cou.country_id = Sta.hp_country_id
INNER JOIN hp_district Dis ON Sta.state_id = Dis.hp_state_id
INNER JOIN hp_city Cit ON Dis.district_id = Cit.hp_district_id
INNER JOIN hp_location Loc ON Cit.city_id = Loc.hp_city_id
INNER JOIN hp_sub_location Sub_Loc ON Loc.location_id = Sub_Loc.hp_location_id
INNER JOIN hp_property Prop ON Sub_Loc.sub_location_id=Prop.hp_sub_location_id
LEFT JOIN hp_builders Bud ON Prop.hp_builders_id=Bud.builders_id
where (Cou.country_status=1 AND Sta.state_status=1 AND Cou.country_id=1)
AND (Dis.district_name LIKE '%ky%' OR Cit.city_name LIKE '%ky%' OR Loc.location_name …
Run Code Online (Sandbox Code Playgroud)

javascript mysql node.js sequelize.js

1
推荐指数
1
解决办法
1940
查看次数

标签 统计

javascript ×2

node.js ×2

sequelize.js ×2

mysql ×1