Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8999767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:13:25+00:00 2026-06-16T00:13:25+00:00

I have two tables: Posts and Likes And I’m trying to list the posts

  • 0

I have two tables: Posts and Likes

And I’m trying to list the posts that the current logged in user likes. The method looks like the following:

$following = $this->Follower->listFollowing($this->Auth->user('id'));

$this->paginate = array('limit'=>20,'conditions'=>array('Post.id'=>array($following['Follower']['post_id']),'Post.status'=>array(1,2)),'order'=>array('Post.datetime'=>'desc'),
                        'contain'=>array('User','Answer'=>array('User'),'Tag'));

$this->set('posts',$this->paginate());

So basically what I’m trying to do is first query the following (likes) table for all matching rows to the user and then use this array of post ids in my find query to list posts that were in the query.

The listFollowing method in the Follower model looks like:

public function listFollowing($user_id)
    {
        return $this->find('all', array( 
            'conditions' => array('Follower.user_id'=>$user_id) 
        ));
    }

I’m currently getting an error like: Undefined index: Follower [APP/Controller/PostsController.php, line 94] So gonna presume that the way I’m trying to pass the list of post ids from the following in the find query is incorrect.

Can anyone help? Thanks

Edit: Doing a debug on $following gives:

array(
    (int) 0 => array(
        'Follower' => array(
            'id' => '4',
            'user_id' => '6',
            'post_id' => '136'
        ),
        'User' => array(
            'password' => '*****',
            'id' => '6',
            'username' => 'driz',
            'email' => '######'
        ),
        'Post' => array(
            'id' => '136',
            'user_id' => '8',
            'datetime' => '2012-09-11 15:49:52',
            'modified' => '2012-09-16 15:31:38',
            'title' => 'Test Content',
            'slug' => 'Test_content',
            'content' => 'Test Content',
            'status' => '1'
        )
    ),
   (int) 1 => array(
        'Follower' => array(
            'id' => '5',
            'user_id' => '6',
            'post_id' => '133'
        ),
        'User' => array(
            'password' => '*****',
            'id' => '6',
            'username' => 'driz',
            'email' => '######'
        ),
        'Post' => array(
            'id' => '134',
            'user_id' => '8',
            'datetime' => '2012-09-11 15:49:52',
            'modified' => '2012-09-16 15:31:38',
            'title' => 'Test Content 2',
            'slug' => 'Test_content_2',
            'content' => 'Test Content 2',
            'status' => '1'
        )
    )
)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:13:26+00:00Added an answer on June 16, 2026 at 12:13 am

    Couple of questions:

    • Did you checked what query is being executed? If it’s executed then probably the method is correct.
    • is $following being populated? what happens if you debug it?

    • if you are retreiving with ‘all’ then the result will look like this:

    Array(

        [0] => Array
            (
                [ModelName] => Array
                    (
                        [id] => 83
                        [field1] => value1
                        [field2] => value2
                        [field3] => value3
                    )
    
                [AssociatedModelName] => Array
                    (
                        [id] => 1
                        [field1] => value1
                        [field2] => value2
                        [field3] => value3
                    )
    
            )
    )
    

    So you’ll never be able to find something at $following[‘Follower’]. Check Cake’s documentation for this

    Based on you comments, if you need a list of id’s try this inside your method:

    public function listFollowing($user_id)
    {
        return $this->find('list', array(
          'conditions' => array('Follower.user_id'=>$user_id) 
          'fields' => array('Follower.user_id'),
          'recursive' => 0);
    }
    

    The ‘list’ retrieve mode does exactlye that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables like this: TABLE user( id CHAR(100) text TEXT ) TABLE
I have two tables that I join on the id-column, they look like: +-------+
I have a database with two tables, Users and Posts. I'd like to write
I have two tables sturctured like so: Posts Table id content Meta Table id
Current situation I have two tables in my database, one for posts, and one
I have two tables, blogs and posts, with the expected relationship between them. Posts
I have two tables user table user_id | name | 1 | peter |
I have two tables with 10-20 million rows that have GUID primary keys and
I have two tables (tbArea, tbPost) that relate to the following classes. class Area
I have two tables Post (id, ..., creationdate) and Post_Has_Post(parent_id, child_id) . Some Posts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.