我试图构建一个显示用户备忘录表格的视图。 备忘录有一个类型( momo_ type) 和几个作者 - 作者表格由记录组成: < code>id, 备忘录_ id, user_ id, user_ id, preview code > 和MemotType 是 < code> id, remo_ type_ desc code > 。 (Memos 还有一个所有者 (Memo. user_ id), 但简单的查询和我有单独的表格, 工作很好 。
想法是,当我查看一个用户的详细细节时,我将显示一个表格,列出所有备忘录,用户被列为作者,并包括备忘类型(信件、演示文稿等)。
因此,尽管我可以从一个有递归=3的读()中获取我需要的阵列(更多下面的 ),但这个速度很慢,可以检索到一吨的数据,所以我正试图使用内存。 (我可以略去备忘_type_desc,但最终用户想要它。 )
OK, so I put public $actsAs = array( Containable );
in app_model.php
这里要指出的一件大事是,无论MemotType 的额外关联级别如何,我都会得到相同的矩阵。 当我添加 < code>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Warning(512):模型“Memo”与模型“MemoTypes”无关[CORE/cake/libs/model/ behaviors/ conferable.php,第343行
模型协会在下面,这里是用户控制器中的“视图”函数。知道我的Memo/MemoTypes协会有什么问题吗?还是找到()语法?
Edit: Oh, and I m a cake newbie and I inherited this application. PS, the table is built by a foreach in view.ctp, but pagination would sure be better, but no idea where to start. =O
// Trying to get Containable method to work...
$this->set( userstuff , $this->User->find( all , array(
conditions => array( User.id => $id),
contain => array(
Author.user_id ,
Author.precedence ,
Author.memo_id => array(
Memo.memo_type_id => array(
MemoTypes.memo_type_id // <--problem here?
)
)
)
)));
结果:
Array
(
[0] => Array
(
[User] => Array
(
[id] => 1026
[group_id] => 2
[name] => John Doe
[username] => jd20001
[grpnum] => 99
[created] => 2010-03-22 15:08:35
[modified] => 2012-04-05 13:31:15
)
[Author] => Array
(
[0] => Array
(
[user_id] => 1026
[precedence] => 0
[memo_id] => 2579
[Memo] => Array
(
[memo_type_id] => 1
)
)
[1] => Array
(
[user_id] => 1026
[precedence] => 0
[memo_id] => 2583
[Memo] => Array
(
[memo_type_id] => 1
)
)
[2] => Array...
更多:
// Works, but retrieves entire users/memos tables so large memory footprint
$this->User->recursive = 3;
$this->set( user , $this->User->read(null, $id));
用户.php:
var $belongsTo = array(
Group => array(
className => Group ,
foreignKey => group_id
)
);
var $hasMany = array(
Author => array(
className => Author ,
foreignKey => user_id ,
dependent => true
),
Memo => array(
className => Memo ,
foreignKey => user_id ,
dependent => false
)
);
备忘录.php:
var $hasMany = array(
Author => array(
className => Author ,
foreignKey => memo_id ,
dependent => true,
order => precedence
)
);
var $belongsTo = array(
User => array(
className => User ,
foreignKey => user_id ,
conditions => ,
fields => ,
order =>
),
MemoType => array(
className => MemoType ,
foreignKey => memo_type_id ,
conditions => ,
fields => ,
order =>
)
);
Memo_ type. php :
var $hasMany = array(
Memo => array(
className => Memo ,
foreignKey => memo_type_id ,
dependent => false
)
);