代码之家  ›  专栏  ›  技术社区  ›  black sensei

条令1.2必须至少选择一个字段错误。但是实际选中一个

  •  2
  • black sensei  · 技术社区  · 15 年前

    查询的根类(别名b)必须至少选择一个字段

    在一个小型学校酒店预订项目中,这里是有关模式的一部分

    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
    

    为了简单起见,我在某块地上绊倒了一下张贴。所以基本上,我想查询一个月内每天预订的房间的总数和类型,我希望事情简单一些,所以现在我假设预订的时间是24小时,所以现在我只想办理入住手续日期。这里是查询吗

    $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 被选中了,到目前为止我还不明白出去。什么你觉得呢?我做错什么了?感谢您的阅读,并提前感谢您的帮助

    3 回复  |  直到 15 年前
        1
  •  1
  •   greg0ire    15 年前

    我是个新手,我也有同样的问题。删除别名可以使其正常工作。

        2
  •  0
  •   Mr.TK    11 年前

    这是因为根元素的所有字段都是别名-这是一个bug(在Doritine的Jira中有报道,但我找不到它)。

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

    如您所见,b.id和b.checkin_date都有一个别名: b、 id将为sum,签入日期为日期:)

    ->select("SUM(COUNT(b.id)), b.checkin_date as DATE, b.checkin_date, t.name")
    
        3
  •  0
  •   Mahsa Sirous    8 年前

    例如:

    ->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);
    
    推荐文章