Check if entity property exists
you can use getClassMetadata like this:
$columns = $em->getClassMetadata(Car::class)->getColumnNames();
if (in_array($property, $columns)) {
//property exists, code here
}
You can try also: getFieldNames
instead of getColumnNames
Alessandro is right but the exact method hasField()
exists:
$metaCar = $em->getClassMetadata(Car::class)
if ($metaCar->hasField('foo')) {
//property exists
}