I always seem to end up in a position where I need more specific information from a collection than addFilter() can give me. Functions like addAttributeToFilter() are great if you’re working with EAV-based collections like products and categories, but they don’t work with a lot of core Magento collections. In this post I’ll go into some detail on how to use the ->getSelect() function to filter collection results. This post comes with a warning: The methods detailed below are intended primarily for data output, not data manipulation. Be careful saving models returned from your original collection.
Calling $collection->getSelect() on your collection will return a model of class type Varien_Db_Select. This model represents the SQL query that is performed to select your collection. I’ve created a module called Mby_Testmodule, and within it I have a model of type testmodule/comment. Let’s get the Select element and play with it a bit.
View original post 330 more words