帮我在 cakephp 中创建查询
Table
users
id name
1 jaskaran
2 jaswinder
3 here
Games
id games
1 chess
2 criket
3 hokey
4 other
user_games
user_id game_id
1 1
1 2
1 3
2 4
3 2
2 1
现在在用户模型中我已经将 hasMany 与 user_games 一起应用
现在任何用户都可以使用用户名和游戏进行搜索,例如 其中 name="%jas%"且 game_id =1
$this->User->find('all',array('conditions'=>array('user.name like'=>'%jas%','Game.game_id'=>1)));
我的 Game.game_id 条件不是工作属性。我该如何应用这个?
最佳答案
您的条件需要按 Game.id 过滤,而不是 Game.game_id,您的模型中没有字段 game_id 游戏。
$this->User->find('all', array('conditions' => array('User.name LIKE' => '%jas%', 'Game.id' => 1)));
关于php - cakephp查询apply有很多条件运行时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21854807/