Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
123
rated 0 times [  127] [ 4]  / answers: 1 / hits: 24870  / 13 Years ago, fri, february 17, 2012, 12:00:00

I'm trying to follow the Sequelize tutorial on their website.



I have reached the following line of code.



Project.findAll({where: [id > ?, 25]}).success(function(projects) {
// projects will be an array of Projects having a greater id than 25
})


If I tweak it slightly as follows



Project.findAll({where: [title like '%awe%']}).success(function(projects) {
for (var i=0; i<projects.length; i++) {
console.log(projects[i].title + + projects[i].description);
}
});


everything works fine. However when I try to make the search parameter dynamic as follows



Project.findAll({where: [title like '%?%', 'awe']}).success(function(projects) {
for (var i=0; i<projects.length; i++) {
console.log(projects[i].title + + projects[i].description);
}
});


It no longer returns any results. How can I fix this?


More From » node.js

 Answers
3

I think you would do that like this:



where: [title like ?, '%' + 'awe' + '%']


So if you were doing this with an actual variable you'd use:



Project.findAll({where: [title like ?, '%' + x + '%']}).success(function(projects) {
for (var i=0; i<projects.length; i++) {
console.log(projects[i].title + + projects[i].description);
}
});

[#87413] Wednesday, February 15, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tyreem

Total Points: 540
Total Questions: 94
Total Answers: 90

Location: Palestine
Member since Tue, Jul 20, 2021
3 Years ago
;