原则多对一仅返回标识符


Doctrine many-to-one returns only the identifier

我在容量和产品之间有一个单向的多对一关系。当我想在数组集合中获取对象的属性时,我得到"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 ▶}
]

}}

尝试更改映射的获取模式:

http://doctrine-orm.readthedocs.org/en/latest/reference/annotations-reference.html?highlight=fetch#manytoone