Magento 1.9 – How to Add Custom ‘Select’ Statement to Collection

collection;gridmagento-1.9

I am working with custom grid. I have a literal value I need to pass to _prepareColumns(). Rather than setting up a custom renderer, I want to just add the literal value to the main collection.

In mysql it would be something like:

SELECT *, "my literal value" as "my_column" from some_table;

Is there any way I can add this to:

$collection = Mage::getModel('me/mymod')->getCollection();

Else, is there another way I can pass a value from _prepareCollection() to _prepareColumns() without using custom renderer?

Best Answer

please try something like this:

$collection = Mage::getModel('me/mymod')->getCollection();
    $collection->getSelect()
        ->columns(
            array(
                new Zend_Db_Expr("\"my literal value\" as `my_column`")
            )
        );

If I understand you right - this is way you need.

Hope it's helpfull.