dorflv5944 2014-05-17 13:34
浏览 10
已采纳

yii关系HAS_MANY添加条件

I write this line at my controller

<i>
    $model_town=ResTown::model()->with(array('get_by_town'))->findAll(array('limit'=>'3'));
</i>

I need to make get_by_town with limit=3 and user_active=1

I got all records but conditions don't work

  • 写回答

1条回答 默认 最新

  • dplo59755 2014-05-17 16:18
    关注

    If you would like to add condition on related table you should write it inside with() method.

    So, you should get something similar `

    ->with('get_by_town'=>array('limit'=>3, 'user_active'=>1))
    

    But in some cases it can not helps you, because it depends on many things: for example, relation type, join type and so on.

    The easiest way to work with ActiveRecord for me, first of all write down pure sql, and then convert to ActiveRecord representation. Thus, I get optimized query and exactly knowing of what I'm doing %)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?