我创建hasManyThrough表如下图所示:与USER_ID CakePHP的hasManyThrough关系被使用了两次
ID user_ID的friend_id
我也有用户表如下图所示: ID用户名密码
我想有user_id和friend_id均属于与用户的id列的关系。所以我写了下面两种模式:
朋友模型
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' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Friend' => array(
'className' => 'User',
'foreignKey' => 'friend_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
}
用户模型
class User extends AppModel {
var $name = 'User';
var $displayField = 'username';
var $hasMany = array(
'User' => array(
'className' => 'Friend',
'foreignKey' => 'user_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'Friend' => array(
'className' => 'Friend',
'foreignKey' => 'friend_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
}
我不知道为什么,但是当我尝试通过在脚手架控制器查看此,说到与500服务器错误?模型配置是否有错误,导致创建错误的SQL?
好吧,似乎错误是由于Zend Optimizer根据一些论坛。这会在烘烤时产生分割错误!
我无法在第三方托管的服务器上关闭此功能,因此我可能必须移动到本地服务器并进行测试,以便查看Cake错误。下面
确定是错误(这是很长,所以我不打算把所有的,但列出了一个有点想法):
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}()
不要查找错误编号。检查错误是关于什么。 –
Protip:始终在本地服务器上开发,绝不在远程/生产服务器上开发。 – JJJ
OK找到了原因! 我无法使用与相关型号名称相同的关联名称!朋友改朋友已经解决了这个问题! –