How to right insert or update on same Doctrine2 object - php

I have this piece of code:
$entity = $em->getRepository('AppBundle:Representative')->find($soqlObj1['records'][0]['Id']);
if ($entity === null) {
$entity = new Representative();
$em->persist($entity);
}
// we set the values from veeva
$entity->setVeevaRepId($soqlObj1['records'][0]['Id']);
$entity->setEmail($soqlObj1['records'][0]['Email']);
...
$em->flush();
And this is part of the entity Representative:
class Representative
{
/**
* #ORM\Id()
* #ORM\Column(type="string", length=45, nullable=false, unique=true)
* #ORM\GeneratedValue()
* #Expose()
*/
protected $veeva_rep_id;
/**
* #var string
* #ORM\Column(type="string", length=45)
* #Expose()
*/
protected $display_name;
/**
* #var string
* #ORM\Column(type="string", length=255)
* #Expose()
*/
protected $avatar_url = 'https://pdone.s3.amazonaws.com/avatar/default_avatar.png';
/**
* #var string
* #ORM\Column(type="string", length=45)
* #Expose()
*/
protected $rep_type = "VEEVA";
/**
* #var string
* #ORM\Column(type="string", length=45)
* #Expose()
*/
protected $username;
/**
* #var string
* #ORM\Column(type="string", length=45)
* #Expose()
*/
protected $first;
/**
* #var string
* #ORM\Column(type="string", length=45)
* #Expose()
*/
protected $last;
/**
* #var string
* #ORM\Column(type="string", length=45, nullable=true)
* #Expose()
*/
protected $title;
/**
* #var string
* #ORM\Column(type="text", nullable=true)
*/
protected $bio;
/**
* #var string
* #ORM\Column(type="string", length=45, nullable=true)
* #Expose()
*/
protected $phone;
/**
* #var string
* #ORM\Column(type="string", length=45)
* #Expose()
*/
protected $email;
/**
* #var bool
* #ORM\Column(type="boolean")
* #Expose()
*/
protected $inactive = false;
/**
* #var \DateTime
* #ORM\Column(type="datetime", nullable=true)
* #Expose()
*/
protected $lastLoginAt;
/**
* #var \DateTime
* #ORM\Column(type="datetime")
* #Expose()
*/
protected $lastSyncAt;
/**
* #var Territory
* #ORM\ManyToOne(targetEntity="Territory")
* #ORM\JoinColumn(name="territories_id", referencedColumnName="veeva_territory_id")
* #Expose()
*/
protected $territory;
/**
* #var string
* #ORM\Column(type="string", nullable=true, length=150)
*/
protected $repTokenId;
...
}
There are a few others columns that are required at DB level (nullable = false at entity level), my question: if the object doesn't exists at DB it will be created or update based on the code I wrote or I need to move each required field into conditional? Which is the right way to achieve this? I am trying to do a INSERT|UPDATE based on just one query result

If you retrieved object from db, doctrine itself knows if the next operation will be an update or an insert: you don't have to worry about anything
Your answer is a valid one but I would modify it as follows
$entity = $em->getRepository('AppBundle:Representative')->find($soqlObj1['records'][0]['Id']);
if ($entity === null) {
$entity = new Representative();
}
// we set the values from veeva
$entity->setVeevaRepId($soqlObj1['records'][0]['Id']);
$entity->setEmail($soqlObj1['records'][0]['Email']);
$em->persist($entity);
$em->flush();
As I told you, you don't have to worry about insertion or update, doctrine will do it for you. However, if you need to set certain values only if the object is a new one or if it was fetched from db, just add proper code under $entity === null control

Related

Doctrine & Symfony - No hydratation data from custom query

Good afternoon,
I try to get all data with one DQL query in a specific Repository.
The problem is, even if I have Host & Page[] (collection), the query returns null values for this entities.
This is my entities ([EDIT] after question by delboy1978uk):
/**
* #ORM\Entity(repositoryClass="App\Repository\WebsiteRepository")
*/
class Website
{
/**
* #var int|null $id
*
* #ORM\Id
* #ORM\Column(type="integer")
*/
private $id;
/**
* #var string $domainName
*
* #ORM\Column(type="string", length=255, nullable=false)
*/
private $domainName;
/**
* #var string $language
*
* #ORM\Column(type="string", length=2, nullable=false)
*/
private $language;
/**
* #var Host $host
*
* #ORM\ManyToOne(targetEntity="App\Entity\Host", cascade={"persist"})
* #ORM\JoinColumn(name="host_id", referencedColumnName="id", nullable=false)
*/
private $host;
/**
* #var ArrayCollection $pages
*
* #ORM\OneToMany(targetEntity="App\Entity\Page", mappedBy="website", cascade={"persist"})
*/
private $pages;
/**
* Website constructor.
*/
public function __construct()
{
$this->pages = new ArrayCollection();
}
}
/**
* #ORM\Entity(repositoryClass="App\Repository\HostRepository")
*/
class Host
{
/**
* #var int|null $id
*
* #ORM\Id
* #ORM\Column(type="integer")
*/
private $id;
/**
* #var string|null
*
* #ORM\Column(type="string", length=255, nullable=false)
*/
private $legalName;
/**
* #var string|null
*
* #ORM\Column(type="string", length=255, nullable=false)
*/
private $address;
/**
* #var string|null
*
* #ORM\Column(type="string", length=15, nullable=false)
*/
private $phoneNumber;
}
/**
* #ORM\Entity(repositoryClass="App\Repository\PageRepository")
*/
class Page
{
/**
* #var int|null $id
*
* #ORM\Id
* #ORM\GeneratedValue
* #ORM\Column(type="integer")
*/
private $id;
/**
* #var string|null $title
*
* #ORM\Column(type="string", length=255, nullable=false)
*/
private $title;
/**
* #var string|null $route
*
* #ORM\Column(type="string", length=255, nullable=false)
*/
private $route;
/**
* #var string|null $template
*
* #ORM\Column(type="string", length=255, nullable=false)
*/
private $template;
/**
* #var Website $website
*
* #ORM\ManyToOne(targetEntity="App\Entity\Website", inversedBy="pages")
*/
private $website;
}
This is my method to find configuration ([EDIT] after question by delboy1978uk):
class WebsiteRepository extends ServiceEntityRepository
{
/**
* WebsiteRepository constructor.
*
* #param ManagerRegistry $registry
*/
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Website::class);
}
public function findConfiguration(): array
{
return $this->getEntityManager()->createQuery(
'SELECT w
FROM App\Entity\Website w
JOIN w.host h
LEFT JOIN w.pages p'
)->getResult();
}
}
I expect to returns Host & Page[] (collection) from findConfiguration method in WebsiteRepository.
Thanks you for your help.
This is the solution with findConfiguration method in WebsiteRepository for findConfiguration method:
SELECT w, h, p
FROM App\Entity\Website w
LEFT JOIN w.host h
LEFT JOIN w.pages p

Doctrine Entity won't serialize with JMS Serializer

I have one entity that won't serialize with JMS Serializer. It throws no errors just a blank screen. If I expose this entity in any of it's related entities it responds with a blank page. I've been poking at this for over a day and it's become quite frustrating. What would keep an entity from being serialized JMS Serializer? Here's a snippet of the entity. I can provide any requested material to anyone willing to help me out here.
<?php
namespace TMG\Api\ApiBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
/**
* Property
*
* #ORM\Table(name="Properties")
* #ORM\Entity(repositoryClass="TMG\Api\ApiBundle\Entity\Repository\PropertyRepository")
* #ORM\HasLifecycleCallbacks()
*
* #Serializer\ExclusionPolicy("all")
*/
class Property
{
public function __construct()
{
$this->featuredAmenities = [];
$this->users = new ArrayCollection();
$this->amenities = new ArrayCollection();
$this->contracts = new ArrayCollection();
$this->rates = new ArrayCollection();
$this->photos = new ArrayCollection();
$this->tollFrees = new ArrayCollection();
$this->favorites = new ArrayCollection();
}
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*
* #Serializer\Expose
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="hash", type="string", length=8)
*
* #Serializer\Expose
*/
private $hash;
/**
* #var string
*
* #ORM\Column(name="ax_number", type="string", length=40, unique=true)
*
* #Serializer\Expose
*/
private $axNumber;
/**
* #var string
*
* #ORM\Column(name="property_number", type="string", length=40, nullable=true)
*
* #Serializer\Expose
*/
private $propertyNumber;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*
* #Serializer\Expose
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="contact_name", type="string", length=255, nullable=true)
*
* #Serializer\Expose
*/
private $contactName;
/**
* #var string
*
* #ORM\Column(name="email", type="string", length=255, nullable=true)
*
* #Serializer\Expose
*/
private $email;
/**
* #var string
*
* #ORM\Column(name="fax", type="string", length=255, nullable=true)
*
* #Serializer\Expose
*/
private $fax;
//.....
Try first to expose only your id to check if you have any response, then if you have no more error, I advise you to follow the documentation to check your configuration: http://jmsyst.com/bundles/JMSSerializerBundle

Cant convert onetoone to onetomany in doctrine using symfony2

I got hired about 2 weeks in a company, and my first task was to update and implement new features in an existing software written in symfony2-doctrine. But one of the changes I must make is just breaking my back.
The previous model was: one "cliente" (costumer) could have only one "credito" (credit) and one "credito" could have many "venta" (sales)
The new model should be: one "cliente" (costumer) can have many "credito" and one "credito" can have many "venta" (Im keeping the onetomany association for backwards compatibity)
This is how my entities look like this:
cliente.php
class Cliente {
//put your code here
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* #ORM\Column(type="string")
* #Assert\NotBlank()
*/
protected $nombre;
/**
* #ORM\Column(type="string", unique=true)
* #Assert\NotBlank()
*/
protected $documento;
/**
* #ORM\Column(type="string", nullable=true)
*/
protected $direccion;
/**
* #ORM\Column(type="string", nullable=true)
*/
protected $telefono;
/**
* #ORM\Column(type="string", nullable=true)
*/
protected $celular;
/**
* #ORM\Column(type="string", nullable=true)
* #Assert\Email()
*/
protected $email;
/**
* #ORM\Column(type="string", nullable=true)
*/
protected $ciudad;
/**
* #ORM\Column(type="string", nullable=true)
*/
protected $departamento;
/**
* #ORM\Column(type="string", nullable=true)
*/
protected $referenciaFamiliar;
/**
* #ORM\Column(type="string", nullable=true)
*/
protected $referenciaFamiliarTelefono;
/**
* #ORM\Column(type="string", nullable=true)
*/
protected $referenciaPersonal;
/**
* #ORM\Column(type="string", nullable=true)
*/
protected $referenciaPersonalTelefono;
/**
* #ORM\OneToMany(targetEntity="Credito", mappedBy="cliente", cascade={"all"})
*/
protected $credito;
/**
* #ORM\Column(type="string", nullable=true, length=255)
*/
protected $photo;
/**
* #Assert\File(maxSize="300k", mimeTypes={"image/jpeg","image/png"},mimeTypesMessage="Debe subir una imagen JPG o PNG",maxSizeMessage="La imagen no puede pesar más de 300 kb.")
*/
protected $file;
credito.php
class Credito {
//put your code here
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* #ORM\Column(type="string",nullable=true)
* #Assert\NotBlank()
*/
protected $cc;
/**
* #ORM\Column(type="datetime",nullable=false)
* #Assert\DateTime()
*/
protected $fechaRegistro;
/**
* #ORM\ManyToOne(targetEntity="Cliente",cascade={"persist"})
* #ORM\JoinColumn(name="cliente_id",referencedColumnName="id")
*/
protected $cliente;
/**
* #ORM\OneToMany(targetEntity="Venta", mappedBy="credito",cascade={"all"})
*/
protected $ventas;
/**
* #ORM\OneToMany(targetEntity="Abono", mappedBy="credito",cascade={"persist"})
*/
protected $abonos;
/**
* #ORM\Column(type="datetime",nullable=true)
* #Assert\DateTime()
*/
protected $fechaProximoPago;
/**
* #ORM\Column(type="decimal",scale=3, precision=23)
* #Assert\NotBlank()
*/
protected $valorProximoPago;
/**
* #ORM\Column(type="integer")
* #Assert\NotBlank()
*/
protected $cuotasTotales;
/**
* #ORM\Column(type="integer")
* #Assert\NotBlank()
*/
protected $cuotasPagadas;
/**
* #ORM\ManyToOne(targetEntity="ModoPagoNom")
* #ORM\JoinColumn(name="modo_pago_id",referencedColumnName="id")
*/
protected $modoPago;
/**
* #ORM\Column(type="decimal",scale=3, precision=23)
* #Assert\NotBlank()
*/
protected $valorFinanciado;
/**
* #ORM\Column(type="decimal",scale=3, precision=23)
* #Assert\NotBlank()
*/
protected $cupo;
/**
* #ORM\Column(type="decimal",scale=3, precision=23)
* #Assert\NotBlank()
*/
protected $cupoUsado;
venta.php
class Venta{
//put your code here
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* #ORM\Column(type="datetime")
* #Assert\DateTime()
*/
protected $fecha;
/**
* #ORM\Column(type="datetime")
* #Assert\DateTime()
*/
protected $fechaPrimerPago;
/**
* #ORM\Column(type="string")
* #Assert\NotBlank()
*/
protected $numeroFactura;
/**
* #ORM\Column(type="string")
* #Assert\NotBlank()
*/
protected $numeroAutorizo;
/**
* #ORM\Column(type="decimal",scale=3, precision=23)
* #Assert\Min(limit="0", message="El valor de la factura debe ser positivo")
*/
protected $valorFactura;
/**
* #ORM\Column(type="integer")
* #Assert\Type("integer")
* #Assert\Min(limit="1", message="Debe especificar al menos una cuota")
*/
protected $numeroCuotas;
/**
* #ORM\Column(type="integer")
* #Assert\Min(0)
*/
protected $cuotasPagadas;
/**
* #ORM\ManyToOne(targetEntity="ModoPagoNom")
* #ORM\JoinColumn(name="modo_pago_id",referencedColumnName="id")
*/
protected $modoPago;
/**
* #ORM\ManyToOne(targetEntity="Credito",cascade={"persist"})
* #ORM\JoinColumn(name="credito_id",referencedColumnName="id")
*/
protected $credito;
/**
* #ORM\Column(type="decimal",scale=3, precision=23)
* #Assert\Min(0.0)
*/
protected $valorFinanciado;
/**
* #ORM\Column(type="decimal",scale=3, precision=23)
* #Assert\Min(0.0)
*/
protected $valorCuota;
/**
* #ORM\Column(type="decimal",scale=3, precision=23)
* #Assert\Min(0.0)
*/
protected $valorPrimeraCuota;
/**
* #ORM\ManyToOne(targetEntity="Almacen")
* #ORM\JoinColumn(name="almacen_id",referencedColumnName="id")
*/
protected $almacen;
/**
* Get id
*
* #return integer
*/
The problem is: everytime I insert a new "credito", it wont be linked to the existing "cliente" instead of that, it will try to insert a duplicate entry of "cliente".
I've tried many things but none of them had any effect.
I appreciate any help, cause Im stuck with that.
If further information or code is required I will gladly provide it.
The cascade={"persist"} should be the core of your problem:
class Credito {
......
/**
* #ORM\ManyToOne(targetEntity="Cliente",cascade={"persist"})
* #ORM\JoinColumn(name="cliente_id",referencedColumnName="id")
*/
protected $cliente;
It tells doctrine to persist cleinte always when you persist Credito.
See docs for more details http://doctrine-orm.readthedocs.org/en/latest/reference/working-with-associations.html#transitive-persistence-cascade-operations
Always tell Doctrine how to do in both sides of an association :
// credito.php
/**
* #ORM\ManyToOne(targetEntity="Cliente", inversedBy="credito", cascade={"persist"})
* #ORM\JoinColumn(name="cliente_id",referencedColumnName="id")
*/
protected $cliente;
And
// venta.php
/**
* #ORM\ManyToOne(targetEntity="Credito", inversedBy="ventas", cascade={"persist"})
* #ORM\JoinColumn(name="credito_id",referencedColumnName="id")
*/
protected $credito;

Doctrine - ManyToOne with table between

I want to create model which will have table users with reference to table CustomFieldValue nad table CustomField with reference to CustomFieldValue too. CustomFieldValue will have only id, value and two columns, one from users and second from CustomField. I want to have functionality like a dynamic adding a new fields in registration form. Is this good idea? If yes, please help me with this model, because it doesn't work:
User:
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(type="string", length=25, unique=true)
*/
private $username;
/**
* #ORM\Column(type="string", length=64)
*/
private $password;
/**
* #ORM\ManyToMany(targetEntity="Role", inversedBy="users",cascade={"persist"})
*
*/
private $roles;
/**
* #ORM\Column(type="string", length=60, unique=true)
*/
private $email;
/**
* #ORM\Column(type="string", length=60)
*/
private $sex;
/**
* #ORM\ManyToMany(targetEntity="Region", inversedBy="users")
* #ORM\JoinColumn(name="region", referencedColumnName="id")
*/
private $region;
/**
* #ORM\ManyToMany(targetEntity="Type", inversedBy="users")
* #ORM\JoinColumn(name="type", referencedColumnName="id")
*/
private $type;
/**
* #ORM\Column(name="is_active", type="boolean")
*/
private $isActive;
/**
* #ORM\ManyToOne(targetEntity="CustomFieldValue",inversedBy="id")
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $customValues;
CustomFieldValue:
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="value", type="string", length=255)
*/
private $value;
/**
*ORM\OneToMany(targetEntity="User", mapped-by="id")
*#ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $user;
/**
*#ORM\OneToMany(targetEntity="CustomField", mapped-by="id" )
*#ORM\JoinColumn(name="field_id", referencedColumnName="id")
*/
private $field;
CustomField:
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="type", type="string", length=255)
*/
private $type;
/**
* #var boolean
*
* #ORM\Column(name="required", type="boolean")
*/
private $required;
/**
* #ORM\ManyToOne(targetEntity="CustomFieldValue", inversedBy="id")
* #ORM\JoinColumn(name="customfield_id", referencedColumnName="id")
*/
private $customValues;
Your mapping is a little off:
User Entity Should Be:
/**
* #ORM\ManyToOne(targetEntity="CustomFieldValue", inversedBy="user")
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $customValues;
CustomFieldValue Should Be:
/**
*ORM\OneToMany(targetEntity="User", mappedBy="customValues")
*/
private $user;
/**
*#ORM\OneToMany(targetEntity="CustomField", mappedBy="customValues" )
*/
private $field;
CustomField should be:
/**
* #ORM\ManyToOne(targetEntity="CustomFieldValue", inversedBy="field")
* #ORM\JoinColumn(name="customfield_id", referencedColumnName="id")
*/
private $customValues;
You dont need the join columns when you are calling the mappedBy this already tells doctrine to look for the join column declaration on that field. For the mappedBy and inversedBy fields these are the fields that link the 2 together NOT the actual join column name.

Symfony2 Cascade on Delete

I have two entities:
Warehouses
id | name
---------------------
1 | Warehouse 1
2 | Warehouse 2
Items
id | warehouse_id | name
--------------------------------------
1 | 1 | Item 1
2 | 2 | Item 2
I am wondering how to set the value of warehouse_id to Null if I remove "warehouse 1" from the warehouse table. In all actually I need warehouse_id to be set to NULL on all tables in my db if I remove "warehouse 1".
In my "Items" entity, for example, I have this set up and it does not seem to do anything for me when I remove "warehouse 1"
/**
* #ORM\ManyToOne(targetEntity="WIC\WarehouseBundle\Entity\Warehouse", inversedBy="purchaseOrderLineItemLocation")
* #ORM\JoinColumn(name="warehouse_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
* #Common\Versioned
*/
protected $warehouse;
Here is my full warehouse entity
Is there something in here that I need to set?
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
* #ORM\Column(name="name", type="string", length=255)
* #Common\Versioned
* #Assert\NotBlank(message="Location Name cannot be blank.")
*/
private $name;
/**
* #var string $description
*
* #Common\Versioned
* #ORM\Column(name="description", type="text")
*/
protected $description;
/**
* #var string
* #ORM\Column(name="address", type="string", length=255)
* #Common\Versioned
* #Assert\NotBlank(message="Address cannot be blank.")
*/
private $address;
/**
* #var string
* #ORM\Column(name="address2", type="string", length=255, nullable=true)
* #Common\Versioned
*/
private $address2;
/**
* #var string
* #ORM\Column(name="city", type="string", length=255)
* #Common\Versioned
* #Assert\NotBlank(message="City cannot be blank.")
*/
private $city;
/**
* #var string
* #ORM\Column(name="state", type="string", length=255)
* #Common\Versioned
* #Assert\NotBlank(message="State cannot be blank.")
*/
private $state;
/**
* #var string
* #ORM\Column(name="zip", type="string", length=255)
* #Gedmo\Versioned
* #Assert\NotBlank(message="Zip cannot be blank.")
*/
private $zip;
/**
* #var string
* #ORM\Column(name="country", type="string", length=255, nullable=true)
* #Common\Versioned
*/
private $country;
/**
* #var string
* #ORM\Column(name="phone", type="string", length=255, nullable=true)
* #Common\Versioned
*/
private $phone;
/**
* #var string
* #ORM\Column(name="email", type="string", length=255, nullable=true)
* #Common\Versioned
*/
private $email;
/**
* #var string
* #ORM\Column(name="fax", type="string", length=255, nullable=true)
* #Common\Versioned
*/
private $fax;
/**
* #ORM\OneToMany(targetEntity="WIC\InventoryLocationBundle\Entity\InventoryLocation", mappedBy="inventoryLocation")
*/
protected $inventoryLocations;
/**
* #ORM\ManyToOne(targetEntity="WIC\UserBundle\Entity\User")
* #ORM\JoinColumn(name="created_by", referencedColumnName="id")
* #Common\Blameable(on="create")
*/
private $createdBy;
/**
* #ORM\ManyToOne(targetEntity="WIC\UserBundle\Entity\User")
* #ORM\JoinColumn(name="updated_by", referencedColumnName="id")
* #Common\Blameable(on="update")
*/
private $updatedBy;
/**
* #ORM\ManyToOne(targetEntity="WIC\AccountBundle\Entity\Account", inversedBy="warehouses")
* #ORM\JoinColumn(name="account_id", referencedColumnName="id", nullable=false)
* #Common\Versioned
* #Common\Blameable(on="create")
*/
protected $account;
/**
* #var datetime $created
*
* #Common\Timestampable(on="create")
* #ORM\Column(type="datetime")
*/
private $created;
/**
* #var datetime $updated
*
* #Common\Timestampable(on="update")
* #ORM\Column(type="datetime", nullable=true)
*/
private $updated;
/**
* #ORM\Column(name="deletedAt", type="datetime", nullable=true)
*/
private $deletedAt;
public function __construct()
{
$this->inventoryLocations = new ArrayCollection();
}
You are probably better of keeping it as restrict on delete, then use a doctrine event subscriber to set the reference to null.
http://symfony.com/doc/current/cookbook/doctrine/event_listeners_subscribers.html
This would give you more control over the process, as well as keeping you aware of what your application is doing. Try not to let the framework act on its own when it comes to destruction of data, otherwise you will start creating holes in your application that become difficult to diagnose.

Categories