NodeJS+Sequelize+Jade; Using the hasMany collection on an object <p>I'm working on a nodejs+sequelize+jade web-app to learn nodejs. Everything basic is quite clear but now I want to up the ante. I have object(table) called brand. The object product has a one-to-many relation with brand. What I like to do is to findAll brands and show them in a Jade-template and also list the products under it.</p> <p>Here is some basic code</p> <pre><code>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'}); </code></pre> <p>In the route for showing the brands and products I do;</p> <pre><code> 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}); }); </code></pre> <p>The strangest thing is that I can see a query being fired when the console.log has been executed but it doesn't create a correct query with the primary key of the brand. The query being select * from products where "brand" is null </p> <p>Also I want to know if I'm assigning the sub collection correct to access it in my Jade template by doing like this</p> <pre><code>ul each item in items li(class='brandItem')= item.name ul each product in item.products li=product.name </code></pre>