我有这些表:使用多个型号查找()CakePHP的
表:CREATORS
obs.:I've也试过这样:
表格:POSTS
CreatorModel.php
class CreatorModel extends AppModel {
public $actsAs = array('Containable');
public $hasOne = array('Post');
}
PostModel.php
class PostModel extends AppModel {
public $actsAs = array('Containable');
public $hasOne = array('Creator');
}
IndexController.php
$this->set('posts', $this->Post->find());
index.ctp
var_dump($posts);
继CakeBook会议关于协会 http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html
我应该接受观点的回应:
Array
(
[Post] => Array
(
[id] => 1
[creator_id] => 1
[tags] =>
[title] => Teste
[post] => Maromba
[created] => 2013-04-29 19:14:32
[modified] => 2013-04-29 19:14:32
)
[Creator] => Array
(
[creator_id] => 1
[creator] => Alexandre Moraes
)
)
但我收到此:
Array
(
[Post] => Array
(
[id] => 1
[creator_id] => 1
[tags] =>
[title] => Teste
[post] => Maromba
[created] => 2013-04-29 19:14:32
[modified] => 2013-04-29 19:14:32
)
)
那么,任何想法我做错了什么?
你需要阅读cakephp文档并遵循约定(这很容易)http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html – Nunser 2013-04-29 18:27:16
在db中,更改'creator_id' for'id' in the table'creators' – Nunser 2013-04-29 19:16:39
@nuns,仍然是相同的回应...没有“创建者”键 – Alexandre 2013-04-29 19:18:58