Php 多对一原则只返回标识符
容量和产品之间存在单向多对一关系。 当我想要获取数组集合中对象的属性时,我会得到“null” 映射: ''' http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd“> }Php 多对一原则只返回标识符,php,symfony,doctrine-orm,doctrine,Php,Symfony,Doctrine Orm,Doctrine,容量和产品之间存在单向多对一关系。 当我想要获取数组集合中对象的属性时,我会得到“null” 映射: ''' http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd“> } }尝试更改映射的获取模式: 我尝试了fetch模式,但忘记了提及,它不起作用。它返回NULL到,我只需要它。如果我使用fetch模式,会不会出现任何性能问题?您是从DQL、存储库还是$em->getReference(..)获取此对象?我获取容量:$produ
}尝试更改映射的获取模式:
我尝试了fetch模式,但忘记了提及,它不起作用。它返回NULL到,我只需要它。如果我使用fetch模式,会不会出现任何性能问题?您是从DQL、存储库还是
$em->getReference(..)获取此对象
?我获取容量:$productCapacity=$this->repository->findOneById(1);然后我在模型“getCapacity”上有一个方法,该方法将映射原始帖子中的所有容量
<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 ▶}
]