【发布时间】:2012-11-05 22:50:51
【问题描述】:
我有三个模型
- 用户
- 备注(与帖子相同)
- 友谊
我正在尝试检索由我订阅的用户共享的帖子。
我在 UsersController 中所做的是首先检索了我所有朋友的列表
$lof=$this->User->Friendship->find('all', array('conditions'=>array('Friendship.user_from'=>$this->Auth->user('id')), 'contain'=>array('Friendship.user_to')));
现在我正在尝试显示我朋友分享的所有帖子
$allnotes= $this->User->Note->find('all', array('conditions'=>array('Note.user_id'=>array($lof)), 'order' => array('Note.created DESC')));
这给了我一个错误
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Array' in 'where clause'
SQL Query: SELECT `Note`.`id`, `Note`.`user_id`, `Note`.`notes`, `Note`.`created`, `User`.`id`, `User`.`name`, `User`.`email`, `User`.`username`, `User`.`password`, `User`.`gender`, `User`.`dob`, `User`.`image`, `User`.`tmp_name`, `User`.`search` FROM `fyp`.`notes` AS `Note` LEFT JOIN `fyp`.`users` AS `User` ON (`Note`.`user_id` = `User`.`id`) WHERE `Note`.`user_id` = (Array) ORDER BY `Note`.`created` DESC
我知道我正在尝试添加一个数组,但是当我尝试类似这样的相同查找查询时,它起作用了。
$allnotes= $this->User->Note->find('all', array('conditions'=>array('Note.user_id'=>array(114,115)), 'order' => array('Note.created DESC')));
从 Friendship 表中仅获取 user_to 的值并将其分配给我的查询中的 Note.user_id 的解决方案到底是什么。
【问题讨论】:
-
在你之前的问题中,答案建议给
find('list')而不是find('all')。试试看。find('all')返回一个多维数组,这可能会导致您的问题。