Magento collection filtering 嵌套where条件的简单写法
2015-09-01 20:23
344 查看
只使用$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
OR关系
------------------------------------------------------
min_weight > $weight OR
$weight > max_weight
AND和OR嵌套关系
------------------------------------------------------
min_weight > $weight AND
(
$weight <= max_weight AND max_weight<>NULL
OR
max_weight IS NULL
)
例如: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) ) );
相关文章推荐
- Windows 10 : 使用BCDboot恢复双系统启动
- javascript 闭包学习
- sqlplus登录Oracle时ORA-01017: invalid username/password; logon denied的错误
- 轻松python之文件专题-读取文件专题
- 博客第一篇
- ostream 保存数据出现乱码原因之一
- 给定100亿个网址,如何检测出重复的文件。
- DP 水题 HDU1003
- 文章标题
- 深入理解Java对象序列化
- iOS调试——基础(二)
- mysql审计,可以了解用户对mysql的操作
- (转)Android-onInterceptTouchEvent()和onTouchEvent()总结
- jquery 100%全屏自适应宽可点击左右和焦点的自动切换幻灯片特效
- 开放地址——平法探测散列表
- 黑马程序员——Java 多线程
- UVA705斜线墙内求封闭路径,矩阵扩充与转化
- 010-spark standalone模式Scala版本WordCount代码
- uva 11396 Claw Decomposition(二分图判定 BFS)
- UIView动画和CAAnimation动画