Reputation: 5027
I am trying to pass some attributes to a method throw sequilize.literal
and I get this error.
This is my code :
include: [{
attributes: ["id", "description", "latitude", "longitude", addValue(
sequelize.literal("`subcategories->establishments`.longitude"),
sequelize.literal("`subcategories->establishments`.latitude")), 'virtualColumn'],
model: establishment, as: 'establishments',
required: false
}]
This is my method :
function addValue(value) {
console.log(value)
return value * 100;
}
Do I have the syntax wrong? (s.replace is not a function while using sequelize)
Upvotes: 1
Views: 2020
Reputation: 5027
For everyone who is having this trouble I was unable to call a function like that and having the sequelize.literal inside. This was the way I did it, hope it can help someone.
include: [{
attributes: [
"id",
"description",
"latitude",
"longitude",
[sequelize.literal(' (6371 * acos ( '
+ 'cos( radians(' + latitude + ') ) '
+ '* cos( radians( `subcategories->establishments`.latitude ) ) '
+ '* cos( radians( `subcategories->establishments`.longitude ) - radians(' + longitude + ') )'
+ '+ sin( radians(' + latitude + ') )'
+ '* sin( radians( `subcategories->establishments`.latitude )))) '), 'distance']
],
model: establishment, as: 'establishments',
required: false
}]
Upvotes: 2