Professional Documents
Culture Documents
Notepads
Notepads
User.findAll({
group: ['field']
})
sequelize.sync({logging: false}).then(()=>{
return Model.Rating.findAll({
attributes: [[Sequelize.fn('avg', Sequelize.col('stars')),'rating']]
})
}).then(res => {
res = res.map(r => r.get())
console.log(res);
})
//However, when trying to do the same through the association of "User", I get
separate values instead of getting average.
sequelize.sync({logging: false}).then(()=>{
return Model.User.findOne({
where: {id: 7},
include : [{
model: Model.Rating, as: 'seller_rating',
attributes: [[Sequelize.fn('avg', Sequelize.col('stars')),'rating']]
}],
attributes: {
exclude: ['password']
},
group: ['seller_rating.id', 'user.id'],
})
}).then(res => {
res = res.get()
res.seller_rating = res.seller_rating.map(r => r.get())
console.log(res)
})
Project.findAll({
attributes: [
// specify an array where the first element is the SQL function and the
second is the alias
[Sequelize.fn('DISTINCT', Sequelize.col('country')) ,'country'],
]
}).then(function(country) { })
<tr>
<div class="mb-3">
<td><label for="" class="form-label mt-3">City</label></td>
<td><select class="form-select form-select-lg mt-3" name="city"
id="city" required>
<option selected required>Select one</option>
<option value=""name="city" id="city">New Delhi</option>
<option value=""name="city" id="city">Istanbul</option>
<option value=""name="city" id="city">Jakarta</option>
</select></td>
</div>
</tr>