原则多对一仅返回标识符 [英] Doctrine many-to-one returns only the identifier
本文介绍了原则多对一仅返回标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在容量和产品之间具有单向多对一关系。
当我想获得数组集合中对象的属性时,我得到空。
I have a unidirectional many-to-one relation between capacity and product. When i want to get a property of an object in the array collection i get "null".
映射:
'''
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd>
The mapping: ''' 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 ▶}
]
}
}
推荐答案
尝试更改映射的提取模式:
Try to change the fetch-mode of your mapping:
这篇关于原则多对一仅返回标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文