Note that there are some explanatory texts on larger screens.

plurals
  1. POCakephp hasManyThrough relationship with user_id being used twice
    primarykey
    data
    text
    <p>I have created hasManyThrough table like below:</p> <p>id user_id friend_id</p> <p>I also have users table like below: id username password</p> <p>I want to have both user_id and friend_id belongsTo relation with user's id column. So I have written below two models:</p> <p>Friend model</p> <pre><code>class Friend extends AppModel { var $name = 'Friend'; //The Associations below have been created with all possible keys, those that are not needed can be removed var $belongsTo = array( 'User' =&gt; array( 'className' =&gt; 'User', 'foreignKey' =&gt; 'user_id', 'conditions' =&gt; '', 'fields' =&gt; '', 'order' =&gt; '' ), 'Friend' =&gt; array( 'className' =&gt; 'User', 'foreignKey' =&gt; 'friend_id', 'conditions' =&gt; '', 'fields' =&gt; '', 'order' =&gt; '' ) ); } </code></pre> <p>User model</p> <pre><code>class User extends AppModel { var $name = 'User'; var $displayField = 'username'; var $hasMany = array( 'User' =&gt; array( 'className' =&gt; 'Friend', 'foreignKey' =&gt; 'user_id', 'dependent' =&gt; false, 'conditions' =&gt; '', 'fields' =&gt; '', 'order' =&gt; '', 'limit' =&gt; '', 'offset' =&gt; '', 'exclusive' =&gt; '', 'finderQuery' =&gt; '', 'counterQuery' =&gt; '' ), 'Friend' =&gt; array( 'className' =&gt; 'Friend', 'foreignKey' =&gt; 'friend_id', 'dependent' =&gt; false, 'conditions' =&gt; '', 'fields' =&gt; '', 'order' =&gt; '', 'limit' =&gt; '', 'offset' =&gt; '', 'exclusive' =&gt; '', 'finderQuery' =&gt; '', 'counterQuery' =&gt; '' ) ); } </code></pre> <p>I'm not sure why but when I try to view this via controller in scaffolding, it comes up with 500 server error?? Is there something wrong with the model config that is creating wrong SQL?</p> <p>OK it seems like error is due to Zend Optimizer according to some forums. This is creating Segmentation Fault when baking!</p> <p>I cannot turn off this in the third party hosted server so I might have to move to my local server and test so I can see Cake errors.</p> <p>OK below is the error (it's very long so I'm not going to put all but below gives a bit of an idea):</p> <pre><code>Fatal error: Maximum function nesting level of '100' reached, aborting! in /usr/share/php/cake/libs/debugger.php on line 248 Call Stack: 0.0011 352048 1. {main}() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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