findAll 没有给出 ManyToMany 的输出
findAll gives no output for a ManyToMany
我最近开始使用 Symfony
,但我不明白为什么 statuses
(ManyToMany) 在 findAll
查询中不提供任何输出。
我需要在数据库中输入的 last/current 值。
App\Entity\Service {#752 ▼
-id: 5
-name: "Helpdesk"
-description: null
-url: null
-serviceGroup: App\Entity\ServiceGroup {#728 ▼
-id: 2
-name: "Webserver 2"
-description: null
-services: Doctrine\ORM\PersistentCollection {#729 ▶}
-order_id: 2
}
-order_id: 3
-statuses: Doctrine\ORM\PersistentCollection {#753 ▼
-snapshot: []
-owner: App\Entity\Service {#752}
-association: array:16 [ …16]
-em: Doctrine\ORM\EntityManager {#383 …11}
-backRefFieldName: "services"
-typeClass: Doctrine\ORM\Mapping\ClassMetadata {#675 …}
-isDirty: false
#collection: Doctrine\Common\Collections\ArrayCollection {#754 ▶}
#initialized: false
}
}
//编辑
对于 easyadmin,我已经在 Entity/Service.php 中添加了一个函数,我不能只将它用于 twig tempalte 吗?
public function getLastStatus()
{
return $this->getStatuses()->last();
}
您应该尝试在@ORM\ManyToMany() 内的属性“状态”中修改您的class 服务,方法是添加:fetch="EAGER"(它应该提供所有对象而不仅仅是代理)。
或者您也可以在 ServiceRepository 中创建一个函数 findStatuses(Service $service) 以使用查询生成器获取所有状态。您将在您的 ServiceRepository 中找到它的示例。
我最近开始使用 Symfony
,但我不明白为什么 statuses
(ManyToMany) 在 findAll
查询中不提供任何输出。
我需要在数据库中输入的 last/current 值。
App\Entity\Service {#752 ▼
-id: 5
-name: "Helpdesk"
-description: null
-url: null
-serviceGroup: App\Entity\ServiceGroup {#728 ▼
-id: 2
-name: "Webserver 2"
-description: null
-services: Doctrine\ORM\PersistentCollection {#729 ▶}
-order_id: 2
}
-order_id: 3
-statuses: Doctrine\ORM\PersistentCollection {#753 ▼
-snapshot: []
-owner: App\Entity\Service {#752}
-association: array:16 [ …16]
-em: Doctrine\ORM\EntityManager {#383 …11}
-backRefFieldName: "services"
-typeClass: Doctrine\ORM\Mapping\ClassMetadata {#675 …}
-isDirty: false
#collection: Doctrine\Common\Collections\ArrayCollection {#754 ▶}
#initialized: false
}
}
//编辑 对于 easyadmin,我已经在 Entity/Service.php 中添加了一个函数,我不能只将它用于 twig tempalte 吗?
public function getLastStatus()
{
return $this->getStatuses()->last();
}
您应该尝试在@ORM\ManyToMany() 内的属性“状态”中修改您的class 服务,方法是添加:fetch="EAGER"(它应该提供所有对象而不仅仅是代理)。
或者您也可以在 ServiceRepository 中创建一个函数 findStatuses(Service $service) 以使用查询生成器获取所有状态。您将在您的 ServiceRepository 中找到它的示例。