dsms21398 2012-08-27 22:37
浏览 22
已采纳

Model find返回CakePHP中的所有行

This problem has me very stumped and I hope you can help me out.

I have a model in CakePHP (2.x) that references another model like this:

<?php
App::uses('MyClass2', 'Model');
class MyClass1 extends AppModel {

Later in the class, I call find('all') on MyClass2:

$params = array(
    'MyClass2.user_id' => $user_id
);
$my_class2 = new MyClass2();
$data = $my_class2->find('all', $params);

But instead of returning only the rows that match $user_id, it returns every row in the database. I can confirm that $user_id is being saved in the database correct and is initialized correctly, but it still always returns all the data instead of only the rows that match $user_id. What should I do to get the data from MyClass2 inside of MyClass1 that only matched the correct $user_id?

  • 写回答

1条回答 默认 最新

  • duanlinjian5819 2012-08-27 22:40
    关注

    You need to add the conditions array in params :)

    $params = array(
        'conditions' => array(
            'MyClass2.user_id' => $user_id
        )
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器