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

I have the following issue where I am a bit stuck. I have 3 tables

maincategories
- id
- maincategory

subcategories
- id
- subcategory
- maincategory_id

recipes_subcategories
- id
- recipe_id
- subcategory_id

The Maincategories are shown as a Navigation. I created an element for
this. Everything works fine. The next step I would like to achieve is
to count the amount of recipes for each maincategory.

Right now I use this code in my maincategories_controller:

if(isset($this->params['requested'])) {
     return $this->Maincategory->find('all', array('order'=>array
('Maincategory'=>'asc'), 'recursive' => 0));

}

How do I get the amount of recipes shown with my above Database
struktur? Could someone give me a hint? I am pretty stuck with it and
can't think of a solution. Thank you very much in advance.

Regards Luke


    回覆作者    轉寄  
您必須先登入才能張貼訊息。
若要張貼訊息,您必須先加入此群組
請在留言之前更新您訂閱設定網頁上的暱稱。
您沒有留言所需的權限。
Brendon Kozlowski (Realm)  
檢視個人資料   翻譯為 已翻譯 (查看原文)
 更多選項 7月4日, 上午10時24分
寄件人: "Brendon Kozlowski (Realm)" <Brendon...@hotmail.com>
日期: Fri, 3 Jul 2009 19:24:22 -0700 (PDT)
當地時間: 2009年7月4日(星期六) 上午10時24分
主旨: Re: Count RS for element
You'd probably want to take a look at CounterCache in the book; this
would require a modification (an additional field) to your
maincategories table, and a little bit of code, but would ultimately
be quicker than a separate query.  Another suggestion would be to look
at find('count') if you don't want to modify your tables, and to learn
how caching works (and use it).

On Jul 3, 11:25 am, Luke <eik...@hotmail.com> wrote:


    回覆作者    轉寄  
您必須先登入才能張貼訊息。
若要張貼訊息,您必須先加入此群組
請在留言之前更新您訂閱設定網頁上的暱稱。
您沒有留言所需的權限。
bramu.ss@gmail.com  
檢視個人資料   翻譯為 已翻譯 (查看原文)
 更多選項 7月4日, 下午12時32分
寄件人: "bramu...@gmail.com" <bramu...@gmail.com>
日期: Fri, 3 Jul 2009 21:32:02 -0700 (PDT)
當地時間: 2009年7月4日(星期六) 下午12時32分
主旨: Re: Count RS for element
I am new to Cake PHP but I can give you the sql to get the count

select count(*), maincategory
from maincategories mc, subcategories sc, recipes_subcategories rsc
where mc.id = sc.maincategory_id
AND sc.id = rsc.subcategory_id
AND mc.id = $this->params["category_id"]
group by mc.id

Thanks,
Ramu.

On Jul 3, 8:25 pm, Luke <eik...@hotmail.com> wrote:


    回覆作者    轉寄  
您必須先登入才能張貼訊息。
若要張貼訊息,您必須先加入此群組
請在留言之前更新您訂閱設定網頁上的暱稱。
您沒有留言所需的權限。
Luke  
檢視個人資料   翻譯為 已翻譯 (查看原文)
 更多選項 7月6日, 下午8時47分
寄件人: Luke <eik...@hotmail.com>
日期: Mon, 6 Jul 2009 05:47:46 -0700 (PDT)
當地時間: 2009年7月6日(星期一) 下午8時47分
主旨: Re: Count RS for element
Hi,

I just had a look at the CounterCache, but seem to struggle on the
implementation. I added another field to my maincategories
table:
recipes_count

I suppose I have to add now 'counterCache'=>true to my Maincategory
model, my relationships are currently looking like this

-----------------------------
Maincategory model
-----------------------------
var $hasMany = array('Subcategory' )

-----------------------------
Recipe Model:
-----------------------------
var $belongsTo = array(
                'User' => array(

var $hasAndBelongsToMany = array(
                'Subcategory'=> array(

-----------------------------
Subcategory Model:
-----------------------------
var $belongsTo = array('Maincategory')

var $hasAndBelongsToMany = array(
                'Recipe' => array(

into which Model I have to add the 'counterCache'=>true ?? I have
tried it with the HABTM so into recipe and subcategory model and than
used this:
http://bakery.cakephp.org/articles/view/counter-cache-behavior-for-ha...

Unfortunately this did not work. Of course I would like to have the
counter in the maincategory table, but is this so easy to reach if I
actualy don't save anything into this table when I add a new recipe?

How would counterCache be activated? Do I have to call it up in the
controller aswell?

Any advice will be great.

Luke


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

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