php - cakephp查询apply有很多条件运行时

标签 php mysql cakephp

帮我在 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/

相关文章:

php - 花式网址的工作

git - 在 Composer 项目中使用 VCS 的最佳实践

javascript - 无法调用jquery函数在cakephp 3中工作

php - Doctrine 2 PlainValue 预期

php - 从对象排序数组

php - 在网页中编译 C 程序时出错

mysql - 需要 Node.JS + MySQL 连接池吗?

mysql - "group by"可以不丢失原始行吗?

php - while 循环内部带有 mysql fetch 的 while 循环

cakephp - CAKE PHP 更改日期格式