Sunday, 9 April 2017

sequalize Search in Association

using sequelize 3.30.1

i have two models Category and Product related through association

var Category = sequelize.define('Category', { name: DataTypes.STRING });

};

var Product = sequelize.define("Product", {

price:{type:DataTypes.INTEGER,UNSIGNED:true},
 {
   classMethods: {
   associate: function() {

    Product.belongsTo(Category, {
      foreignKey: {
         name: 'category',
         allowNull: false
      }
    });

});

how can i search for product with Category.name like %CatName% ?



via soofy

No comments:

Post a Comment