excluded excluded - 4 months ago 10
PHP Question

I receive Persitent Collection instead of ArrayCollection

I want to see if my record in database has related photos or not. But when I call

$car->getCarPhotos()
, I get the instance of
Doctrine\ORM\PersistentCollection
, and
var_dump
show the same result for car what has photos, and for car what has no car_photos. Where is my problem? Please , help me.

Answer

So what is bothering you? It is supposed to return you collection in both cases. To check whether car has related photos:

if ($car->getCarPhotos()->isEmpty()) {
    // Car has no photos
} else {
    // Car has photos
}