I have a custom module with a custom table, now I'm trying to do something like a filter for this table,
Mage::getModel('comunity/news')->getCollection()
->addFieldToFilter('title', array('like'=>'%'.$this->getRequest()->getParam('q').'%'));
this is enough, and works fine, but I need to add another field, just if you do
Mage::getModel('comunity/news')->getCollection()
->addFieldToFilter('title', array('like'=>'%'.$this->getRequest()->getParam('q').'%'))
->addFieldToFilter('shortdesc', array('like'=>'%'.$this->getRequest()->getParam('q').'%'));
it works, but it does (AND) and I want (OR), I looked into the Varien_Data_Collection_Db class, the addFieldToFilter function calls the _getConditionSql call, where you can see something like this
if (is_array($fieldName)) {
foreach ($fieldName as $f) {
$orSql = array();
foreach ($condition as $orCondition) {
$orSql[] = '('.$this->_getConditionSql($f[0], $f[1]).')';
}
$sql = '('. join(' or ', $orSql) .')';
}
return $sql;
}
here can be executed (OR), I tried with
->addFieldToFilter(array (
array('field'=>'title', 'like'=>'%'.$this->getRequest()->getParam('q').'%'),
array('field'=>'shortdesc', 'like'=>'%'.$this->getRequest()->getParam('q').'%'),
))
but the request he makes is
SELECT `main_table`.* FROM `uhma_comunidad_articulos` AS `main_table` WHERE (())
I need help here thanks