我有這些表:使用多個型號查找()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