commit e0bd85b2989b7280faa3ba315a2b2252576fe530
parent 3269bbf7d6c8f713dc0c54664a8b8ea3c43e7b93
Author: Timo A. Hummel <felicitus@felicitus.org>
Date: Tue, 7 Jul 2015 16:55:05 +0200
Merge pull request #409 from dunglas/manufacturer_ic_logos
Make the Manufacturer::$icLogos collection working with ApiBundle
Diffstat:
3 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/composer.lock b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "9258045adbaa71263ad5f69963c207a0",
+ "hash": "54d61f1687b5e3cf505fddfdcc843e92",
"packages": [
{
"name": "brainbits/fugue-icons-bundle",
diff --git a/src/PartKeepr/ManufacturerBundle/Entity/Manufacturer.php b/src/PartKeepr/ManufacturerBundle/Entity/Manufacturer.php
@@ -3,6 +3,7 @@ namespace PartKeepr\ManufacturerBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
+use Doctrine\ORM\PersistentCollection;
use PartKeepr\DoctrineReflectionBundle\Annotation\TargetService;
use PartKeepr\UploadedFileBundle\Annotation\UploadedFileCollection;
use PartKeepr\Util\BaseEntity;
@@ -81,7 +82,7 @@ class Manufacturer extends BaseEntity
/**
* All ic logos of this manufacturer
- * @ORM\OneToMany(targetEntity="PartKeepr\ManufacturerBundle\Entity\ManufacturerICLogo",mappedBy="manufacturer",cascade={"persist","remove"})
+ * @ORM\OneToMany(targetEntity="PartKeepr\ManufacturerBundle\Entity\ManufacturerICLogo",mappedBy="manufacturer",cascade={"persist", "remove"}, orphanRemoval=true)
*
* @UploadedFileCollection()
* @Groups({"default"})
@@ -247,12 +248,22 @@ class Manufacturer extends BaseEntity
}
/**
- * Sets the IC Logos
+ * Adds an IC Logo.
*
- * @param array $icLogos The icLogos to set
+ * @param ManufacturerICLogo $icLogo
*/
- public function setIcLogos($icLogos)
- {
- $this->icLogos = $icLogos;
+ public function addIcLogo(ManufacturerICLogo $icLogo) {
+ $icLogo->setManufacturer($this);
+ $this->icLogos->add($icLogo);
+ }
+
+ /**
+ * Removes an IC Logo.
+ *
+ * @param ManufacturerICLogo $icLogo
+ */
+ public function removeIcLogo(ManufacturerICLogo $icLogo) {
+ $icLogo->setManufacturer(null);
+ $this->icLogos->removeElement($icLogo);
}
-}-
\ No newline at end of file
+}
diff --git a/src/PartKeepr/ManufacturerBundle/Entity/ManufacturerICLogo.php b/src/PartKeepr/ManufacturerBundle/Entity/ManufacturerICLogo.php
@@ -33,7 +33,7 @@ class ManufacturerICLogo extends Image
*
* @param Manufacturer $manufacturer The manufacturer to set
*/
- public function setManufacturer(Manufacturer $manufacturer)
+ public function setManufacturer(Manufacturer $manufacturer = null)
{
$this->manufacturer = $manufacturer;
}