Get results with a like condition in JavaScript

R Rens van der Linden 3 years 7 months ago
4 1 0

Hi,

I'm trying to get the results of a find query with a like condition in JavaScript. But i don't know how to do this.

I've found this Ruby solution: (Rhomobile | Rhom Ruby API ):
Product.find(  :all,  :conditions => {  {   :func => 'LOWER',   :name => 'description',   :op => 'LIKE'  } => query,  {   :func => 'LOWER',   :name => 'title',   :op => 'LIKE'  } => query  },  :op => 'OR',  :select => ['title','description']
Product.find( :all, :conditions => [    "LOWER(description) like ? or LOWER(title) like ?",   query,   query ], :select => ['title','description'] )
The like query isn't described in the JavaScript guide, so i've tried this: (Rhomobile | Using Rhom in JavaScript )
var objs = contact.find("all",     offset: offset,    per_page: limit,    conditions: "LOWER(name) like rens"});
var objs = contact.find("all", {    offset: offset,    per_page: limit,    op: 'LIKE',    conditions: "LOWER(name) like rens"});
var objs = contact.find("all", {    offset: offset,    per_page: limit,    conditions: {        name: 'rens',        op: 'LIKE'    }});
It doesn't work for me. What is the right way to do this in JavaScript?

Can someone help me? Thanks.

Please Register or Login to post a reply

1 Replies

R Rens van der Linden

The solution is to execute a sql query like this:

SELECT L.object AS object, L.VALUE AS column1, R.VALUE AS column1FROM object_values L INNER JOIN object_values R ON L.object = R.objectWHERE L.attrib = column1AND R.attrib = column2AND column1 LIKE '%test%'
The model I used is a PropertyBag. So I can't use "SELECT * FROM tablename". When I switch to a fixedModel this will be possible, but there are a lot of disadvantages. See more info: Rhomobile | Using Rhom in Ruby

Use this to execute the query:

var database = new Rho.Database(Rho.Application.databaseFilePath('user'),'user');var result = database.executeSql("here_the_query");
And then loop through the results...

CONTACT
Can’t find what you’re looking for?