English 中文(简体)
与使用可控制、模范协会的深层协会的查找()
原标题:Find() with Deep Associations using Containable, Model associations

我试图构建一个显示用户备忘录表格的视图。 备忘录有一个类型( momo_ type) 和几个作者 - 作者表格由记录组成: < code>id, 备忘录_ id, user_ id, user_ id, preview 和MemotType 是 < code> id, remo_ type_ desc 。 (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
    )
);
问题回答

我终于能读得更多(在张贴我的问题之后,

用户和组给我我的主要信息, 然后Memo让我建一个自有文件的表格, 而作者给了我所有文件的数据, 其中用户被列为作者! 哇, 在与CakePHP Im合作了一年之后,

$this->set( user , $this->User->find( first , array(
     conditions  => array( User.id  => $id),
     contain  => array(
         Group ,
         Memo ,
         Author  => array(
             Memo  => array(
                 MemoType  => array(
                     fields  => array( memo_type_desc )
                )
            )
        )
    )
)));




相关问题
CakePHP 1.3 controller save() does not save data

I want to add a new user to the database, and do so by making them fill in a form and submitting this. All seems to work fine. Just before my save() call in the controller I return all data and all ...

Cakephp 1.3 database migration with

I am using cakephp 1.3 on LAMP (ubuntu 9.04) platform. Trying the database migration with cakephp inbuilt schema generation script. I am inside the app folder & When i fire a command in the ...

CakePHP 1.3.0 RC4 Installation

I have been using 1.2.6 and downloaded 1.3 to try it out. I am using wampserver with Apache 2.2.11. I have mod rewrite enabled. When I bake a new application using the cake 1.3 console, after I verify ...

Cakephp 1.3 JsHelper for AjaxHelper

I m start using cakephp and i made a demo app using AjaxHelper $ajax->link( title , url , array( update => mydiv )) Now i want to migrate that to cakephp 1.3 and AjaxHelper is deprecated on ...