首页 > 其他 > 详细

Magento collection filtering 嵌套where条件的简单写法

时间:2015-09-01 21:30:13      阅读:317      评论:0      收藏:0      [点我收藏+]
只使用$collection->addFieldToFilter(),不使用addAttributeToFilter()或者Zend_Db_Expr(可用于更复杂的where语句)
例如:collection->getSelect()->where(new Zend_Db_Expr("(e.created_at > ‘2013-01-01 00:00:00‘ OR e.created_at <‘2012-01-01 00:00:00)"));
 
AND关系
------------------------------------------------------
min_weight < $weight AND
max_weight >= $weight 
 
$_collection->addFieldToFilter(‘min_weight‘, array(‘lt‘ => $weight))
->addFieldToFilter(‘max_weight‘, array(‘gteq‘ => $weight));

 

 
OR关系
------------------------------------------------------
min_weight > $weight OR
$weight > max_weight
 
$_collection->addFieldToFilter(
array(‘min_weight‘,‘max_weight‘),
    array(
        array(‘gt‘ => $weight),
        array(‘lt‘ => $weight)
    )
);    

 

 
AND和OR嵌套关系
------------------------------------------------------
min_weight > $weight AND
(
$weight <= max_weight AND max_weight<>NULL
OR
max_weight IS NULL
)
 
$_collection->addFieldToFilter(‘min_weight‘, array(‘lt‘ => $weight))
->addFieldToFilter(
    array(‘max_weight‘,‘max_weight‘),
    array(
        array(‘gteq‘ => $weight, ‘notnull‘ => true),
        array(‘null‘ => true)
    )
);            

 

Magento collection filtering 嵌套where条件的简单写法

原文:http://www.cnblogs.com/kogen/p/4776786.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!