4

I want to get the where condition from a collection.I'm using it in my sales order grid.

$collection = $this->getCollection();
echo $this->getCollection()->getSelect();

When i apply getselect to the collection i could see the corresponding query with where condition:

 SELECT `main_table`.*, `myorder`.`customer_email` FROM `sales_flat_order_grid` AS `main_table` 
     LEFT JOIN `sales_flat_order` AS `myorder` ON myorder.entity_id = main_table.entity_id 
     WHERE (`main_table`.`status` = 'received') 
     ORDER BY main_table.created_at DESC LIMIT 20 

But I want to know is there any other way to get where condition directly from the collection itself.

I want to apply that where to another query of mine.

3

You can get the select part in this way:

$where = $collection->getSelect()->getPart(Zend_Db_Select::WHERE);

There is also a setPart() method that can be used to set where condition.


Other possible parts from Zend_Db_Select are:

/**
 * The initial values for the $_parts array.
 * NOTE: It is important for the 'FOR_UPDATE' part to be last to ensure
 * meximum compatibility with database adapters.
 *
 * @var array
 */
protected static $_partsInit = array(
    self::DISTINCT     => false,
    self::COLUMNS      => array(),
    self::UNION        => array(),
    self::FROM         => array(),
    self::WHERE        => array(),
    self::GROUP        => array(),
    self::HAVING       => array(),
    self::ORDER        => array(),
    self::LIMIT_COUNT  => null,
    self::LIMIT_OFFSET => null,
    self::FOR_UPDATE   => false
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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