2010-10-10 25 views
2

我一直在敲我的頭撞在牆上了有關此異常過去一小時:學說1.2必須選擇Error.but一個至少一個字段實際上選擇

的根類查詢(別名二)必須至少有一個字段在這裏一所小學校酒店預訂項目選擇

關注

RoomType: 
    actAs: [Timestampable] 
    tableName: room_type 
    columns: 
    name: string(100) 
    number_of_bed: integer 

Room: 
    tableName: room 
    columns: 
    id: 
     type: string(36) 
     primary: true 
    room_number: integer 
    price: decimal 
    relations: 
    RoomType: 
     class: RoomType 
     local: type_id 
     foreign: id 

RoomBooking: 
    tableName: roombooking 
    actAs: [Timestampable] 
    columns: 
    id: 
     type: string(36) 
     primary: true 
     room_id: string(36) 
     checkin_date: date 
     checkout_date: date 
     is_cancelled: boolean 
    relations: 
    Room: 
     class: Room 
     local: room_id 
     foreign: id 
架構的一部分

我絆倒了然而在特定的n字段爲簡單起見和短post.So基本上我想查詢總數,特定月份的每一天預訂的房間類型。我想要的事情很簡單,所以現在我假設預訂只是24小時,所以爲現在我只是希望在籤date.here是查詢

$q = Doctrine_Query::create() 
->select("SUM(COUNT(b.id)), b.checkin_date as DATE, t.name") 
->from ("Hotel_Model_RoomBooking b") 
->leftJoin("b.Room r") 
->leftJoin("r.RoomType t") 
->where ("b.checkin_date > ? AND b.checkin_date < ?", array ($first, $last)) 
->groupBy("b.checkin_date, t.name"); 

$result = $q->fetchArray();  

b.checkin_date是,所以我有這個和b.id選擇的根類的一個領域,到現在爲止我想不出它out.What你認爲?我在這裏做錯了什麼?感謝您的閱讀和預先感謝您的幫助

回答

1

我是新來的教義和我有同樣的問題。刪除別名使其工作。

0

這是因爲根元素的所有字段都是別名 - 這是一個錯誤(它在Doctrine的Jira中有報道,但我找不到它)。

->select("SUM(COUNT(b.id)), b.checkin_date as DATE, t.name") 

正如你可以看到,兩者b.id和b.checkin_date,有一個別名: b.id將總和,CHECKIN_DATE是DATE :) 有關問題的最簡單的燈具是:

->select("SUM(COUNT(b.id)), b.checkin_date as DATE, b.checkin_date, t.name") 
0

你需要在你的數據庫中擁有所有primary_key這是你的選擇。例如: :

->select('(pol.quantity * pol.price) as actual_material_cost') 
     ->addSelect('p.project_id') 
     ->addSelect('pol.purchase_order_line_id') 
     ->addSelect('ri.requisition_item_id') 
     ->addSelect('pt.project_task_id') 
     ->addSelect('polri.purchase_order_line_req_item_id') 
     ->from('PurchaseOrderLines pol') 
     ->leftJoin('pol.PurchaseOrderLineReqItems polri') 
     ->leftJoin('polri.RequisitionItems ri') 
     ->leftJoin('ri.ProjectTasks pt') 
     ->leftJoin('pt.Projects p') 
     ->where('p.project_id = ?' , $project_id); 
相關問題