Country.hasMany(City, { foreignKey: 'country_id' });
City.belongsTo(Country, { foreignKey: 'country_id' });
City.hasMany(Walk, { foreignKey: 'city_id' });
Walk.belongsTo(City, { foreignKey: 'city_id' });
Walk.hasMany(Point, { foreignKey: 'walk_id' });
查询字段:
walks: Db.models.dl_walk.findAll({
where: {
$or: [
{
name: { like: `%${args.search}%` }
}
]
}
})
search="NameCountry"
时,如何获取当前国家和所有"行走"
在当前的国家?
答案 0 :(得分:0)
要查找属于某个国家/地区的所有步行,您需要进行关联查询 像
这样的东西Model.Country.findAll({where:/*some criteria*/,
include:[{model: Model.city, include: model.walk}]
})
这将使联接查询从国家/地区开始到步行