多对一主义只返回标识符

时间:2014-12-15 17:38:18

标签: php symfony doctrine-orm doctrine

我在容量和产品之间存在单向的多对一关系。 当我想获得数组集合中对象的属性时,我得到" null"。

映射: '''    http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="\Capacity" table="capacity">
        <id name="id" type="integer">
             <generator strategy="AUTO" />
        </id>

        <!-- Relation: product -->
        <many-to-one field="product" target-entity="IDT\Component\Paylogic\Model\Product">
             <join-column name="product_id"      referenced-column-name="uid"  nullable="false" />
        </many-to-one>
    </entity>
</doctrine-mapping>

方法:

<?php

class Capacity 
{
    public function getCapacity()
    {
        // Validate the capacity.
        $productsAndCapacity = $this->getProductCapacities()->map(function($entity)  {
          dump($entity->getProduct()->getName());
          die;
        })->toArray();

   return $productsAndCapacity;
}

转储的对象:

PersistentCollection {#430 ▼
-snapshot: []
-owner: null
-association: null
-em: null
-backRefFieldName: null
-typeClass: null
-isDirty: false
-initialized: true
-coll: ArrayCollection {#431 ▼
    -_elements: array:2 [▼
      0 => Capacity {#432 ▼
        #id: 3
        #product: Product {#512 ▼
          +__isInitialized__: false
          #uid: "de4b1153f3854d6b9e6230704c1ffe88"
          #name: null
          #subtitle: null
          #availability: null
          #maxPerOrder: null
          #minPerOrder: null
          #price: null
          #separatelySaleable: null
          #soldOut: null
          #soldOutText: null
          #event: null
          #shippingMethods: null
          #paymentMethods: null
          #createdAt: null
          #updatedAt: null
          #uri: null
          #lastSyncedAt: null
       …4
    }
    #maxCapacity: 5
    #currentCapacity: 0
    #ticketUrl: TicketUrl {#418 ▶}
    #createdAt: DateTime {#510 ▶}
    #updatedAt: DateTime {#509 ▶}
  }
  1 => Capacity {#508 ▶}
]

} }

1 个答案:

答案 0 :(得分:0)