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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:29:56+00:00 2026-06-08T12:29:56+00:00

I am new to CakePHP so please be easy on me. I have this

  • 0

I am new to CakePHP so please be easy on me.

I have this issue that I don’t seem to be able to solve. I have a “contact” table and would like this table to have a many to many relationship with itself. The objective is to show that a contact is related to other contacts from the same company. So when clicking a contact’s profile, I will be able to view other contacts that are related to that particular person.

I have no idea how to approach this issue. I’m thinking of a join table but doesn’t seem to be possible? or I might be wrong. If anyone has any idea how to do this, please leave as much detail as possible so that I can understand how to do this (as I’m new to CakePHP as stated earlier).

Thanks!!

Edit: Tried the method stated by User996302 but still not working.

This is a portion of the Contact model for the relationship:

public $hasAndBelongsToMany = array( 'Relation' => array( 'className' => 'Contact', 'joinTable' => 'contacts_contacts', 'foreignKey' => 'contact_id', 'associationForeignKey' => 'related_id', 'unique' => true, 'conditions' => '', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '', 'finderQuery' => '', 'deleteQuery' => '', 'insertQuery' => '' ) ); 

I am using the saveAll function in the controller.
In the add section of the controller, I have this at the end:

$relations = $this->Contact->Relation->find('list');     $this->set(compact('relations'));

In the add view page I have this line of code to display the selection box:

echo $this->Form->input('Relation', array('type'=>'select', 'multiple' => true));

I have a contacts and a contacts_contacts table. The contacts_contacts table has three attributes: id, contact_id, related_id.

I have done all these but the selection list in the form does not display any contact that I can choose from.
Not sure where the problem is. Any help will be great!

  • 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-08T12:29:57+00:00Added an answer on June 8, 2026 at 12:29 pm

    Those links should help you: example, SO question on the question.

    Edited to correct a mistake.

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

Sidebar

Related Questions

I'm new to cakephp so go easy on me! I have a table called
I'm new to cakephp and following this tutorial. http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html I have created the blog
I'm new to testing, so please forgive me for this question In the cakephp
I'm using the new CakePHP 2.1 and would like to use the JsonView to
I am new to cakephp and I'm trying to accomplish something that should be
I am using cakePHP 1.26. In the PostsController, I have this: $this->paginate=array('conditions'=>array('Reply.post_id'=>$id),'limit' => 1);
I would like to extend the cakephp logging facility. Using $this->log($msg, $level) you can
i'm very new to this cakephp & i got an assignment to fix an
I have a backend data management console written with CakePHP that allows a user
Please forgive me, I am still fairly new to cakephp and in the process

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.