0
我试图在cakephp 3中的两个模型(服务器和application_endpoints)表之间创建关联。我想实现的是将所有数据从application_endpoints表中获取到服务器模型。所以在视图中我可以访问所有的数据。CakePHP 3在两个表之间关联
服务器可以在application_endpoints表中具有多个VIP和端点,并且我正在使用hasMany关联。因此,在ServersTable.php我添加下面的代码:
$this->hasMany('ApplicationEndpoints', [
'foreignKey' => 'server_id',
'dependent' => true
]);
所以,当我浏览服务器视图页面,点击调试工具包变量选项卡里面,我没有看到任何连接。我看到阵列中的服务器列表,但阵列中的每个服务器都不显示与application_endpoints表的任何关系。
请评论并让我知道如果它不清楚,我也链接sqlfiddle关于mysql模式。
更新1
我也ServersTable.php尝试这种代码,以及:
$this->belongsTo('ApplicationEndpoints', [
'bindingKey' => 'server_id',
'joinType' => 'INNER',
]);