dongwuwu6104 2014-04-11 10:55
浏览 21

Cake PHP:在更深层次的递归上查找条件

My Models are related as follows:

Post BELONGS_TO Parent
Parent HAS_MANY ParentAdmin 

Now I wish to find all Parent admins of all post if a post's attribute's value is met. The equivalent sql query is :

SELECT parent_admins.* FROM posts 
LEFT JOIN parents AS Parent ON Parent.id = posts.target_id    
LEFT JOIN parent_admins ON parent_admins.parent_id = Parent.id 
WHERE posts.admin_notification = 0 AND Parent.maxtime > posts.created

Assuming Models are linked in cakephp accordingly and recursive = 2, what will be the condition array in find query?

  • 写回答

3条回答 默认 最新

  • dtf54486 2014-04-11 11:16
    关注

    You can both use the bindModel & unbindModel methods to get the exact query you want or you can use the Containable behavior.

    More information about how to create and destroy associations on the fly with CakePHP: http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#creating-and-destroying-associations-on-the-fly

    And you'll need this array of conditions:

    $conditions = array(
        'Post.admin_notification' => 0,
        'Parent.maxtime >' => 'Post.created'
    );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)