我正在使用 CakePHP 构建一个 json Rest api。它工作得很好,除了我似乎无法得到正确的响应结构。
我有两个表:Users 和 Profiles。用户有一个配置文件。Profiles 有一个外键。模型:Users.php(使用 public $hasOne = 'Profile'),Profiles.php 控制器:UsersController.php
回应是:
[2] => Array
(
[User] => Array
(
[id] => 3
[firstname] => test
[lastname] =>
[email] =>
[password] =>
[created] => 2012-09-04 16:44:04
[modified] => 2012-09-04 16:44:04
)
[Profile] => Array
(
[id] =>
[skill] =>
[user_id] =>
)
)
我真的希望回复是这样的:
[2] => Array
(
[User] => Array
(
[id] => 3
[firstname] => test
[lastname] =>
[email] =>
[Profile] => Array
(
[id] =>
[skill] =>
[user_id] =>
)
)
)
我查看了 join()、bind()、containable...我似乎找不到嵌套表的解决方案。有什么想法可以让 Profile 嵌套在用户中?