我有两个实体:
仓库
id | name --------------------- 1 | Warehouse 1 2 | Warehouse 2
项目
id | warehouse_id | name -------------------------------------- 1 | 1 | Item 1 2 | 2 | Item 2
如果我从仓库表中删除“仓库 1”,我想知道如何将warehouse_id 的值设置为 Null。实际上,如果我删除“仓库 1”,我需要在我的数据库中的所有表上将仓库 ID 设置为 NULL。
例如,在我的“项目”实体中,我已经设置了这个,当我删除“仓库 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;
这是我的完整仓库实体
这里有什么我需要设置的吗?
/**
* @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();
}