-2

I recently started using Symfony and I don't understand why statuses(ManyToMany) don't give any output on a findAll query. I need there the last/current value that was entered in the database.

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
  }
}

//Edit for easyadmin I have already added a function in the Entity/Service.php, can't I just use this for the twig tempalte?

public function getLastStatus()
{
    return $this->getStatuses()->last();
}
Tealk
  • 49
  • 1
  • 7

1 Answers1

1

You should try to modify your class Service in your property "statuses" inside @ORM\ManyToMany() by adding : fetch="EAGER" (it should give the all object and not just the proxy).

Or you can also create a function findStatuses(Service $service) in your ServiceRepository that get all the statuses using the query builder. You will find exemples of it in your ServiceRepository.

Bahamut0
  • 34
  • 2