所有網頁 圖片 影片 地圖 新聞 網誌搜尋 Gmail 更多 »
最近造訪的群組 | 說明 | 登入
Google 網上論壇首頁
Table join confusion...
目前本群組有太多主題設為優先顯示。要優先顯示這個主題,請將其他主題的這個選項取消。
在處理您的要求時發生錯誤。請再試一次。
標幟
  9 個訊息 - 全部摺疊  -  將全文翻譯為 已翻譯 (查看所有原文)
您要留言的群組是 Usenet 群組。在此群組留言,網際網路上的任何使用者將可以看到您的電郵地址。
您的回覆郵件尚未寄出。
您已成功留言
 
寄件人:
收件人:
副本:
後續追蹤對象:
新增副本 | 新增後續追蹤對象 | 編輯主旨
主旨:
驗證:
為了確認,請輸入您在以下圖片中看到的字元,或輸入您按下存取圖示時所聽到的號碼。 注意聽並輸入您聽到的號碼
 
jakobjp  
檢視個人資料   翻譯為 已翻譯 (查看原文)
 更多選項 11月8日, 上午2時48分
寄件人: jakobjp <m...@jakobjp.net>
日期: Sat, 7 Nov 2009 10:48:55 -0800 (PST)
當地時間: 2009年11月8日(星期日) 上午2時48分
主旨: Table join confusion...
I need a little assistance with a join over 3 tables.

I have the following Models (User > Profile > Infogroup >
Information):
- User (hasMany Profile)
- Profile (belongsTo User, hasMany Infogroup)
- Infogroup (belongsTo Profile, hasMany Information)
- Information (belongsTo Infogroup)

The relationships are defined in the model classes, and there is no
problem getting the associated data, when for example fetching a User.

However, what do I need to do to get all Information that belongs to a
specific User?

I.e. all rows from the informations table "where
Information.infogroup_id = Infogroup_id AND Infogroup.profile_id =
Profile.id AND Profile.user_id = XYZ"?


    回覆    回覆作者    轉寄  
您必須先登入才能張貼訊息。
若要張貼訊息,您必須先加入此群組
請在留言之前更新您訂閱設定網頁上的暱稱。
您沒有留言所需的權限。
Thiago Nuic Vidigal  
檢視個人資料   翻譯為 已翻譯 (查看原文)
 更多選項 11月8日, 上午3時35分
寄件人: Thiago Nuic Vidigal <tvidi...@gmail.com>
日期: Sat, 7 Nov 2009 17:35:18 -0200
當地時間: 2009年11月8日(星期日) 上午3時35分
主旨: Re: Table join confusion...

You can include other tables in the query using the 'joins' option of the
Model->find method.


    回覆    回覆作者    轉寄  
您必須先登入才能張貼訊息。
若要張貼訊息,您必須先加入此群組
請在留言之前更新您訂閱設定網頁上的暱稱。
您沒有留言所需的權限。
kdubya  
檢視個人資料   翻譯為 已翻譯 (查看原文)
 更多選項 11月19日, 上午4時24分
寄件人: kdubya <kenwin...@winanstech.com>
日期: Wed, 18 Nov 2009 12:24:59 -0800 (PST)
當地時間: 2009年11月19日(星期四) 上午4時24分
主旨: Re: Table join confusion...
On Nov 7, 2:35 pm, Thiago Nuic Vidigal <tvidi...@gmail.com> wrote:

> You can include other tables in the query using the 'joins' option of the
> Model->find method.

This sound like the solution to a problem I am trying to solve but I
have looked in the Manual and can find almost nothing about "joins"
option to "find()'. Can you give an example of a "find()" that uses
"joins"? I am looking for the specific syntax.

Thank you,
Ken


    回覆    回覆作者    轉寄  
您必須先登入才能張貼訊息。
若要張貼訊息,您必須先加入此群組
請在留言之前更新您訂閱設定網頁上的暱稱。
您沒有留言所需的權限。
Dr. Loboto  
檢視個人資料   翻譯為 已翻譯 (查看原文)
 更多選項 11月19日, 上午11時51分
寄件人: "Dr. Loboto" <drlob...@gmail.com>
日期: Wed, 18 Nov 2009 19:51:37 -0800 (PST)
當地時間: 2009年11月19日(星期四) 上午11時51分
主旨: Re: Table join confusion...
http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-...

Minimal code for join:
$this->find(
    'all',
    array (
        'joins' => array (
            array (
                'table' => 'my_table',
                'alias' => 'MyTable',
                'conditions' => 'MyTable.foreign_key = '.$this-

>alias.'.id'

            )
        )
    )
);

On Nov 19, 2:24 am, kdubya <kenwin...@winanstech.com> wrote:


    回覆    回覆作者    轉寄  
您必須先登入才能張貼訊息。
若要張貼訊息,您必須先加入此群組
請在留言之前更新您訂閱設定網頁上的暱稱。
您沒有留言所需的權限。
Josh  
檢視個人資料   翻譯為 已翻譯 (查看原文)
 更多選項 11月19日, 下午12時45分
寄件人: Josh <joshs.silver...@gmail.com>
日期: Wed, 18 Nov 2009 20:45:04 -0800 (PST)
當地時間: 2009年11月19日(星期四) 下午12時45分
主旨: Re: Table join confusion...
Hello,

Have you set recursive to 2 in your find options array (http://
book.cakephp.org/view/439/recursive)? When querying your User model,
that should get you the profile and infogroups.

As for joining Information to your infogroups, I am not sure if
recursive = 2 will automatically join to that depth. Try binding
Information to the Infogroup model before querying. When working from
the User model:

            $this->Profile->Infogroup->bindModel(
                array('hasMany' => array('Information'))
            );

Since this will take you to three levels of recursion, you might also
want to unbind any extra models.

Let me know what works for you. I have never needed to join past
recursive = 2.

Good luck.

On Nov 18, 3:24 pm, kdubya <kenwin...@winanstech.com> wrote:


    回覆    回覆作者    轉寄  
您必須先登入才能張貼訊息。
若要張貼訊息,您必須先加入此群組
請在留言之前更新您訂閱設定網頁上的暱稱。
您沒有留言所需的權限。
kdubya  
檢視個人資料   翻譯為 已翻譯 (查看原文)
 更多選項 11月20日, 下午9時45分
寄件人: kdubya <kenwin...@winanstech.com>
日期: Fri, 20 Nov 2009 05:45:01 -0800 (PST)
當地時間: 2009年11月20日(星期五) 下午9時45分
主旨: Re: Table join confusion...
Dr. Lobato,

Thank you. I don't know why I didn't find this article on the bakery
but it looks just what I need. Your example code is very clear. I'll
try it today.

Ken

On Nov 18, 10:51 pm, "Dr. Loboto" <drlob...@gmail.com> wrote:

<snip>

    回覆    回覆作者    轉寄  
您必須先登入才能張貼訊息。
若要張貼訊息,您必須先加入此群組
請在留言之前更新您訂閱設定網頁上的暱稱。
您沒有留言所需的權限。
Dave  
檢視個人資料   翻譯為 已翻譯 (查看原文)
 更多選項 11月21日, 上午3時52分
寄件人: Dave <davidcr...@gmail.com>
日期: Fri, 20 Nov 2009 14:52:33 -0500
當地時間: 2009年11月21日(星期六) 上午3時52分
主旨: Re: Table join confusion...

Probably because if you follow naming convention cake handles all of the
necessary joins for you behind the scenes.  You should definitely check your
recursive value as the previous poster mentioned as well as your database
relationships set in your model.  Usually User hasOne Profile I would think,
so with hasMany you may get quite a few profile results depending on your
find call.


    回覆    回覆作者    轉寄  
您必須先登入才能張貼訊息。
若要張貼訊息,您必須先加入此群組
請在留言之前更新您訂閱設定網頁上的暱稱。
您沒有留言所需的權限。
Josh  
檢視個人資料   翻譯為 已翻譯 (查看原文)
 更多選項 11月21日, 下午12時08分
寄件人: Josh <joshs.silver...@gmail.com>
日期: Fri, 20 Nov 2009 20:08:21 -0800 (PST)
當地時間: 2009年11月21日(星期六) 下午12時08分
主旨: Re: Table join confusion...
@kdubya

I was curious about recursions past a depth of 2 so I ran some tests
on a data model I'm currently working with. Apparently you can set
recursive as high as you want. In your case you would want $this-

>recursive = 3 (when writing in the context of your model)

Be sure to unbind unnecessary model relations! Cake will not only join
to whatever depth you want, but it will also rejoin domains so you'd
have information repeated in your resulting array (if you don't unbind
the the belongsTo relation going in the other direction).

If you get your model relations correct, this is a REALLY easy way to
achieve what you are looking for.

Josh

On Nov 20, 2:52 pm, Dave <davidcr...@gmail.com> wrote:


    回覆    回覆作者    轉寄  
您必須先登入才能張貼訊息。
若要張貼訊息,您必須先加入此群組
請在留言之前更新您訂閱設定網頁上的暱稱。
您沒有留言所需的權限。
Jesh  
檢視個人資料   翻譯為 已翻譯 (查看原文)
 更多選項 11月22日, 上午3時04分
寄件人: Jesh <joshs.silver...@gmail.com>
日期: Sat, 21 Nov 2009 11:04:16 -0800 (PST)
當地時間: 2009年11月22日(星期日) 上午3時04分
主旨: Re: Table join confusion...
whoops. I meant to address that last comment to jakobjp

On Nov 20, 11:08 pm, Josh <joshs.silver...@gmail.com> wrote:


    回覆    回覆作者    轉寄  
您必須先登入才能張貼訊息。
若要張貼訊息,您必須先加入此群組
請在留言之前更新您訂閱設定網頁上的暱稱。
您沒有留言所需的權限。
無其他留言
« 返回討論主題 « 較新的主題     較舊的主題 »

建立群組 - Google 網上論壇 - Google 首頁 - 服務條款 - 隱私權政策
©2009 Google