0

This is v1.4.x to be clear.

I have recently found a limitation in the Magento-generated query for products, cited in this thread:

adding addFieldsToFilter() does INNER JOIN on eav tables, removing all products which don't have that attribute

On that subject, I started searching for a way to pass a complete SQL query to the model, but have not found any way listed. Is this possible? Again, this is a limited case and Magento unfortunately does an INNER JOIN with no remedy when I need a LEFT JOIN.

1 Answer 1

0

I'll answer this for future readers, ignoring the fact that you don't need it anymore because there is a simple solution to your original problem.

You can modify the Zend_Db_Select instance for any collection, which means that you can effectively change the query to anything.

Here is a simple and stupid example:

$collection->getSelect()->reset(Zend_Db_Select::WHERE)->where('foo=bar');

But be aware that many collections make their own changes in the _beforeSave() method or using an observer.

2
  • Although this is not passing the entire query, the where clause is what I wanted to modify (all other Magento methods seem to be accommodating), and a solution has been posted to my other question referenced above. Thanks for not being a "forum snob" and answering the specific question I gave. :) Commented Mar 11, 2016 at 13:48
  • 1
    Actually "where" was just an example, if you have a look at Zend_Db_Select you will see that you can modify other parts as well Commented Mar 11, 2016 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.