I have three Models
- User
- Note ( Same as Post )
- Friendship
I am trying to retrieve posts that are shared by the users to whom i am Subscribed to.
What exactly i did in my UsersController is that i first retrieved the list of all of my friends
$lof=$this->User->Friendship->find('all', array('conditions'=>array('Friendship.user_from'=>$this->Auth->user('id')), 'contain'=>array('Friendship.user_to')));
Now i am trying to show all the posts shared by my friends
$allnotes= $this->User->Note->find('all', array('conditions'=>array('Note.user_id'=>array($lof)), 'order' => array('Note.created DESC')));
Which gives me an error
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
I know i am trying to add an array but when i tried the same find query like this, it worked.
$allnotes= $this->User->Note->find('all', array('conditions'=>array('Note.user_id'=>array(114,115)), 'order' => array('Note.created DESC')));
What exactly is the solution to get only the values of user_to from Friendship table and assign it equals to Note.user_id in my query.
find('list')rather thanfind('all'). Try that.find('all')returns a multidimensional array which is likely causing your issue. - Ross