Hey using Doctrine ORM with attribute GeoData
/**
* @var GeoData[]|Collection
*
* @ORM\ManyToMany(targetEntity="Acme\Bundle\CoreBundle\Entity\GeoData", inversedBy="addresses", cascade="persist", fetch="LAZY")
* @ORM\JoinTable(name="users__addresses_geodata")
*/
protected $geoData;
and with a special getter to acquire first element of GeoData
public function getMostLocalGeoDatum(): ?GeoData
{
if (null == $this->geoData && $this->geoData->isEmpty()){
return null;
}
/** @var GeoData $localeGeoDatum */
$localeGeoDatum = $this->geoData->first();
return $localeGeoDatum;
}
but everytime I use this getter, I get a error:
TypeError: Return value of ACME\Bundle\CoreBundle\Entity\Address::getMostLocalGeoDatum() must be an instance of ACME\Bundle\CoreBundle\Entity\GeoData or null, boolean returned
Any clue what might be wrong? According to Doctrine ArrayCollection documentation, first() should return first element of ArrayCollection.
The first
ifshould not beand, instead it should be anorcondition.