1

I have Company and Client entities. Clients - are employees of companies. I want to be able to delete a company in my script. I got it. Together with the company removes all of its employees (instances of the class Client).But I need something different. I just need that field "clients_company_id" became NULL.Namely, I deleted the company, its customers (employees) have remained in the database but Client's clients_company_id = Null.Here's what I need

/**
 * @ORM\Entity(repositoryClass="AmgradeCRM\ContactsBundle\Entity\Repository\CompanyRepository")
 * @ORM\Table(name="company")
 * @ORM\HasLifecycleCallbacks()
 */
class Company
{
/**
 * id
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

    /**
 * Clients relating to this company
 * @ORM\OneToMany(targetEntity="AmgradeCRM\ContactsBundle\Entity\Client", mappedBy="company", cascade={"persist", "remove"}))
 */
protected $clients;

and Client entity

/*
* client
* @ORM\Entity
* @ORM\Table(name="client")
*/
class Client
{
/**
 * id
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

    /**
 * company of this client
 * @ORM\ManyToOne(targetEntity="AmgradeCRM\ContactsBundle\Entity\Company", inversedBy="clients")
 * @ORM\JoinColumn(name="clients_company_id", referencedColumnName="id")
 */
protected $company;

0 Answers0