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 6682971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:46:03+00:00 2026-05-26T04:46:03+00:00

Sorry for the non-descript title, but I’m not sure how to phrase it. Currently,

  • 0

Sorry for the non-descript title, but I’m not sure how to phrase it. Currently, I am trying my hand at developing a Twitter clone with cakePHP, since I’m new to web programming. I have gone with 3 tables:

users (id, name)

  • id is the auto-generated id
  • name of the user

tweets (id, content, user_id)

  • id is the auto-generated id
  • content is the text of the tweet
  • user_id is the id of the user that made the post

followers (id, user_id, following_id)

  • id is the auto-generated id
  • user_id is the user who is doing the following
  • following_id is the user that is being followed

Now, almost everything is basically working, even the follow function somewhat. However, I think I may have set up the model relationships wrong. In fact, I’m pretty sure it’s wrong.

Right now, these are the model relationships:

  • User: has many Tweets, has many Followers
  • Tweets: belongs to User
  • Followers: belongs to User

I’m pretty sure the Followers relationship is wrong, but that’s what I’ve been working with. Right now, what works is the user login/logout, sessions, posting, deleting your own posts, and following other uses (and then being able to see their tweets).

What doesnt work right now is when I try to get a list of people I’m following or people that is following me. The problem is I’m not sure how to access that data.

I want to have a screen where I can click on a link to see all the people I’m following and then see all of their latest tweets.

For example, I believe I can do a use a find() query to get a list of all the people I’m following, but as you can see from the Follower table above, that query only returns the user IDs of the follower and followee. From that data, how do I get access to their names and latest tweet?

Do I do two lookups? Is it something I can redefine in my model relationships, so that when in my ctp file, I can just php look through and use something like:

$this->$data['Tweet']['userID']
$this->$data['User']['name']
$this->$data['Tweet']['content']

I’m sorry, I’m not sure if I explained myself correctly…

I do hope my intention is clear however. Any advice is appreciated!

Thank you!

  • 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-05-26T04:46:03+00:00Added an answer on May 26, 2026 at 4:46 am
    app/models/user.php
    
    class User extends AppModel{
          var $name = 'User';
    
          var $hasAndBelongsToMany = array(
                'Follower' => array(
                      'className'             => 'Follower',
                      'joinTable'             => 'user_users',
                      'foreignKey'            => 'user_id',
                      'associationForeignKey' => 'child_user_id'
                )
          )
    }
    
    app/models/follower.php
    
    class Follower extends AppModel{
          var $name     = 'Follower';
          var $useTable = 'users';
    }
    

    You will have to make a table user_users with the fields user_id and child_user_id. child_user_id would be the follower ID, you could name it follower id if you want but it might be confusing if you need to make a similar relation in the future.

    Try it out.

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

Sidebar

Related Questions

SQL Server 2008: Sorry for the possibly non-informative title but I'm not sure quite
sorry for the title but I'm not sure how I should call it. I'm
Sorry for how vague the title is, but I'm not completely sure how to
Sorry for the non-descript title, but I'm having a hard way with words right
Sorry for the non-technical title, but I think it summarizes my question well. If
Sorry but I am not sure how to ask this question but I am
Sorry for the non-descriptive title but I don't know whether there's a word for
Sorry for the title, not easy to phrase it correctly. I have a table
Sorry if the title is vague, I'm not sure what terminology to use. Here
Sorry for the bad title - I simply do not know what to call

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.