1
나는 nodejs + sequelize + jade web-app에서 nodejs를 배우고 있습니다. 기본은 모두 분명하지만 지금은 분담금을 높이고 싶습니다. 브랜드라는 객체 (테이블)가 있습니다. 대상 제품은 브랜드와 일대 다 관계를 맺습니다. 내가하고 싶은 것은 모든 브랜드를 찾아서 Jade-template에 표시하고 그 아래에 제품을 나열하는 것입니다. 여기 NodeJS + Sequelize + Jade; 객체에 hasMany 컬렉션 사용하기
내가 할 브랜드와 제품을 표시하기위한 경로에서 몇 가지 기본적인 코드var Brand = sequelize.import(application_root + "/models/brand.js");
var Product = sequelize.import(application_root + "/models/product.js");
Brand.hasMany(Product, { as: 'Products', foreignKey: 'brand'});
Product.belongsTo(Brand, { foreignKey: 'key'});
이다;
Brand.findAll().error(errorHandler).success(function(brands)
{
brands[0].getProducts().success(function(products) {
brands[0].products = products;
});
res.render('listOfbrands.jade', { title: 'List of brands', items: brands});
});
이상한 것은
내가 CONSOLE.LOG이 실행 된 경우 쿼리가 해고되고 있지만,이 브랜드의 기본 키와 올바른 쿼리를 생성하지 않습니다 볼 수 있다는 것입니다. "브랜드는"null의 제품에서 선택 *되는 쿼리는또한 나는이이
ul
each item in items
li(class='brandItem')= item.name
ul
each product in item.products
li=product.name