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!