2017-01-06 83 views
2

今天早上我遇到了一個愚蠢的問題,我很難找到一個體面的解決方案。也許你可以提示我...沒有會話cookie的主體對象不完整,爲什麼?

我有這個簡單的功能,在實體存儲庫,用一個簡單的查詢:

public function findAvailabilityByDr($delivery_round_id) { 
    $qb = $this->_em->createQueryBuilder() 
     ->select('partial dro.{id}, 
        partial drp.{id, maxDeliveries, countDeliveries}, 
        partial zdd.{id, day}, 
        partial rer.{id, maxOrders, countOrders}') 
     ->from($this->_entityName, 'dro') 
     ->leftJoin('dro.parts', 'drp') 
     ->leftJoin('drp.day', 'zdd') 
     ->leftJoin('drp.relayRounds', 'rer') 
     ->where('dro.id = :delivery_round_id') 
     ->setParameters(array(
      'delivery_round_id' => $delivery_round_id, 
     )); 

    dump($qb->getQuery()->getOneOrNullResult()); 
    die(); 
} 

在第一負載(用創建無會話cookie),我得到了一個不完整的結果:

DeliveryRound {#342 ▼ 
    -id: 117 
    -endOfOrdersDate: DateTime {#346 ▶} 
    -parts: PersistentCollection {#428 ▼ 
    -snapshot: array:2 [ …2] 
    -owner: DeliveryRound {#342} 
    -association: array:15 [ …15] 
    -em: EntityManager {#695 …11} 
    -backRefFieldName: "deliveryRound" 
    -typeClass: ClassMetadata {#373 …} 
    -isDirty: false 
    #collection: ArrayCollection {#412 ▼ 
     -elements: array:2 [▼ 
     0 => DeliveryRoundPart {#425 ▼ 
      -id: 134 
      -deliveryDate: DateTime {#347 ▶} 
      -deliveryHourStart: null 
      -deliveryHourEnd: null 
      -maxDeliveries: null <------ HERE !!!!!!!!!!! 
      -countDeliveries: null 
      -deliveryRound: DeliveryRound {#342} 
      -day: ZoneDeliveryDay {#1302 ▶} 
      -ordersCustomers: PersistentCollection {#358 ▶} 
      -ordersProviders: PersistentCollection {#410 ▶} 
      -relayRounds: PersistentCollection {#637 ▶} 
      -roadSheetOptimizationData: null 
     } 
     1 => DeliveryRoundPart {#1444 ▶} 
     ] 
    } 
    #initialized: true 
    } 
    -ordersProvidersGenDate: null 
    -roadSheetPath: null 
    -roadSheetGenDate: null 
    -preparationSheetPath: null 
    -preparationSheetGenDate: null 
    -deliveryMailNotificationsSendingDate: null 
    -deliveryNotificationsSendingDate: null 
    #translations: PersistentCollection {#420 ▶} 
    #newTranslations: null 
    #currentLocale: "fr" 
    #defaultLocale: "fr" 
} 

,並在第二個電話(刷新),創建會話cookie,結果是正確的(maxDeliveries:30是正確的):

DeliveryRound {#1657 ▼ 
    -id: 117 
    -endOfOrdersDate: null 
    -parts: PersistentCollection {#1794 ▼ 
    -snapshot: array:2 [ …2] 
    -owner: DeliveryRound {#1657} 
    -association: array:15 [ …15] 
    -em: EntityManager {#695 …11} 
    -backRefFieldName: "deliveryRound" 
    -typeClass: ClassMetadata {#1673 …} 
    -isDirty: false 
    #collection: ArrayCollection {#1795 ▼ 
     -elements: array:2 [▼ 
     0 => DeliveryRoundPart {#1747 ▼ 
      -id: 134 
      -deliveryDate: null 
      -deliveryHourStart: null 
      -deliveryHourEnd: null 
      -maxDeliveries: 30 <------ HERE !!!!!!!!!!! 
      -countDeliveries: 0 
      -deliveryRound: DeliveryRound {#1657} 
      -day: ZoneDeliveryDay {#2063 ▶} 
      -ordersCustomers: PersistentCollection {#1904 ▶} 
      -ordersProviders: PersistentCollection {#1896 ▶} 
      -relayRounds: PersistentCollection {#2187 ▶} 
      -roadSheetOptimizationData: null 
     } 
     1 => DeliveryRoundPart {#2188 ▶} 
     ] 
    } 
    #initialized: true 
    } 
    -ordersProvidersGenDate: null 
    -roadSheetPath: null 
    -roadSheetGenDate: null 
    -preparationSheetPath: null 
    -preparationSheetGenDate: null 
    -deliveryMailNotificationsSendingDate: null 
    -deliveryNotificationsSendingDate: null 
    #translations: PersistentCollection {#1799 ▶} 
    #newTranslations: null 
    #currentLocale: "fr" 
    #defaultLocale: "fr" 
} 

當我用QB-$> getQuery() - > getArrayResult() 結果是在這兩種情況下是正確的。

跆拳道?它是錯誤嗎?

感謝您的幫助!

編輯

如果我將其降低到最簡單的表達,沒有局部的和從控制裝置的呼叫,這個錯誤仍然存​​在......

庫:

public function findAvailabilityByDr($delivery_round_id) { 
    $qb = $this->_em->createQueryBuilder() 
     ->select('dro, 
        drp') 
     ->from($this->_entityName, 'dro') 
     ->leftJoin('dro.parts', 'drp') 
     ->where('dro.id = :delivery_round_id') 
     ->setParameters(array(
      'delivery_round_id' => $delivery_round_id, 
     )); 

    return $qb->getQuery()->getOneOrNullResult(); 
} 

控制器:

class StructureController extends BasePublicCommonController 
{ 
    public function indexAction() 
    { 
     $delivery_round = $this->getDoctrine()->getManager()->getRepository('ProxymartDeliveryBundle:DeliveryRound')->findAvailabilityByDr(117); 
     dump($delivery_round); 
     die(); 
    } 
} 

這是這樣的事情我討厭有時編程:)

+0

也deliveryDate在第一次調用,而不是在第二次調用返回...我從來沒有要求它在查詢...看來,學說在第一次調用時更改我的查詢。奇。 – wewereweb

+0

你可以嘗試選擇'DRP。*' – COil

+0

同樣的事情...所有的DRP值爲空。在第二個電話中工作... :( – wewereweb

回答

-1

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/partial-objects.html

我不知道該cookie,但我知道arrayResult():

局部一般來說,對象問題不適用於不以對象的形式檢索查詢結果的方法或查詢。例如:查詢#getArrayResult()[...]

+0

我將用它來進行這個特定的查詢,因爲這次我不需要保存數據。但它仍然是一個奇怪的錯誤。也許我可以嘗試更新PHP和SF。不管怎麼說,還是要謝謝你。 – wewereweb

+0

或者,也許我應該強制重新加載時沒有檢測到cookie,因爲創建會話cookie時,一切正常。 – wewereweb

+0

是的,對不起,我不能幫助更多 – goto

相關問題