I have this entity:
class Brand
{
...
/**
* @var Company
* @ORM\ManyToOne(targetEntity="Company", inversedBy="brands")
* @ORM\JoinColumn(name="companies_id", referencedColumnName="id", nullable=true)
*/
protected $company;
...
/**
* Set company.
*
* @param Company $company
*
* @return Brands
*/
public function setCompany(Company $company)
{
$this->company = $company;
return $this;
}
}
If I remove the Company type-hint from the method signature, I get this error:
Catchable Fatal Error: Argument 1 passed to AppBundle\Entity\Brand::setCompany() must be an instance of AppBundleEntity\Company, null given, called in /var/www/html/backend/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php on line 410 and defined
I set the property to nullable but I can't remove the object from the data, why? How this can be fixed?
setCompany(Company $company=null)to preserve type safety and allow nulls. - Anonymous