Note that there are some explanatory texts on larger screens.

plurals
  1. POCakephp HABTM: Model not accessible in controller
    text
    copied!<p>I am trying to work with HABTM association between Profiles and Qualifications tables.</p> <p>Model: Profile.php</p> <pre><code>App::uses('AppModel', 'Model'); class Profile extends AppModel { public $hasAndBelongsToMany = array( 'Qualifications' =&gt; array( 'className' =&gt; 'Qualification', 'joinTable' =&gt; 'profile_qualifications', 'foreignKey' =&gt; 'profile_id', 'associationForeignKey' =&gt; 'qualification_id', 'unique' =&gt; 'keepExisting' ) ); } </code></pre> <p>Model: Qualification.php</p> <pre><code>App::uses('AppModel', 'Model'); class Qualification extends AppModel { public $hasAndBelongsToMany = array( 'Profile' =&gt; array( 'className' =&gt; 'Profile', 'joinTable' =&gt; 'profile_qualifications', 'foreignKey' =&gt; 'qualification_id', 'associationForeignKey' =&gt; 'profile_id', 'unique' =&gt; 'keepExisting', ) ); } </code></pre> <p>Controller: ProfilesController.php</p> <pre><code>App::uses('AppController', 'Controller'); class ProfilesController extends AppController { public function add() { $qualifications = $this-&gt;Qualification-&gt;find('list'); /* Attempt 1 */ $qualifications = $this-&gt;Profile-&gt;Qualification-&gt;find('list'); /* Attempt 2 */ $qualifications = $this-&gt;Profile-&gt;ProfileQualification-&gt;Qualification-&gt;find('list'); /* Attempt 3 */ } } </code></pre> <p>All three attempts mentioned as comment have given me an error saying:</p> <pre><code>Error: Call to a member function find() on a non-object File: ~/app/Controller/ProfilesController.php Line: xxx </code></pre> <p>I want to know how can I generate a list of all entries in Qualifications table ? Moreover, what is the mistake in my code right now ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload