0

I have a condition that I'm always adding on some of the models on the init. It's a authorization condition. When I add a grid with a model that has this condition, and I add a quick search I get unexpected behavior. Both conditions are there, the one that I've added and the one generated by the quick search, but they are connected with "OR" so nothing works because of it.

I think the conditions should be linked together like this:

select * from my_model
where 
 (condition_added_with_addCondition1) AND (condition_added_with_addCondition2) 
 AND (condition_from_quicksearch1 or condition_from_quicksearch2)

In my example I have used addCondition twice and added two seach boxes using addQuickSearch.

zadof
  • 69
  • 5
  • well it seems to be OK to me. conditions you add are connected with "and" but because quicksearch must find match only in one column, its connected with OR. Could you explain why you think it's a wrong behavior? – romaninsh Apr 28 '12 at 22:34
  • because the quick search doesn't really filter anything out, it's useless. Let's say you add a condition in the init of a model field1 = 'value' and then you add a quick search to a grid which has that model set. Now your grid will initially show all the records that have the field1='value' (the where clause will be field1='value'). When you type something in the quick search for field2 let's say, your condition will be "where field1='value' or field2 like '%text on quick search'%". How will this filter out results? You get the same results no matter what you type. – zadof Apr 30 '12 at 13:12
  • Actually I am a little wrong, because the result is even more unpredictable. I use the filter on the init model for security reasons, to allow only admins to see some data, but the quick search messes things up. – zadof Apr 30 '12 at 13:17
  • I still don't see how it's wrong. "or" is inside brackets. – romaninsh May 01 '12 at 00:52
  • Because you get into a situation when by typing a value in the quick search you get more records than without typing anything. You are supposed to filter out data with the search, not get more. – zadof May 01 '12 at 13:55
  • I see why we are not on the same page, my field is calculated, and it's being added to the HAVING, same as the quicksearch, and not in the WHERE clause. I also see there is a TODO question in the code about this... – zadof May 01 '12 at 14:35
  • I've changed line 283 in to lib/Model/Table.php $this->_dsql()->where($field->expr . $cond . $value); and it works great for my needs but might not be the best solution – zadof May 01 '12 at 14:51

0 Answers0