Forráskód Böngészése

Merged in FD3-686 (pull request #23)

Fix foreign-key > node-cablemodem
Maximiliano Schvindt 6 éve
szülő
commit
82c6d79356

+ 4 - 4
composer.lock

@@ -1458,7 +1458,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/BaseAdmin.git",
-                "reference": "a9b57ea652fa0cfe12a32c3135860bb9bcfe0453"
+                "reference": "7f9681db582387e43645139671f724cf07c0392f"
             },
             "type": "library",
             "autoload": {
@@ -1473,7 +1473,7 @@
                 "bootstrap",
                 "sonata"
             ],
-            "time": "2018-09-04T16:04:16+00:00"
+            "time": "2018-09-12T14:56:27+00:00"
         },
         {
             "name": "ik/device-bundle",
@@ -1691,7 +1691,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@gogs.infra.flowdat.com:222/VendorSoftwareFlowdat3/WorkflowBundle.git",
-                "reference": "a929fd734fdeee5a7b91d4eba944c7e39ccdb384"
+                "reference": "68b4100b1162b313ae53e6cd25119188b3acdcfa"
             },
             "require": {
                 "php-amqplib/rabbitmq-bundle": "^1.12"
@@ -1721,7 +1721,7 @@
                 "bundle",
                 "workflow"
             ],
-            "time": "2018-09-03T11:59:55+00:00"
+            "time": "2018-09-06T15:45:57+00:00"
         },
         {
             "name": "incenteev/composer-parameter-handler",

+ 2 - 2
src/CablemodemBundle/Entity/Cablemodem.php

@@ -79,8 +79,8 @@ class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationIn
     protected $activationCode;
 
     /**
-     * @ORM\ManyToOne(targetEntity="Node", fetch="EXTRA_LAZY", cascade={"persist"})
-     *
+     * @ORM\ManyToOne(targetEntity="Node", fetch="EXTRA_LAZY")
+     * @ORM\JoinColumn(name="node_id", referencedColumnName="id", onDelete="SET NULL")
      * @JMS\MaxDepth(1)
      */
     protected $node;

+ 42 - 4
src/CablemodemBundle/Entity/Node.php

@@ -2,19 +2,21 @@
 
 namespace CablemodemBundle\Entity;
 
-use Base\AdminBundle\Interfaces\PreRemoveInterface;
+use Base\AdminBundle\Traits\TenancyIdTrait;
+use Base\AdminBundle\Traits\TenancyIdTraitInterface;
 use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\ORM\Mapping as ORM;
 use JMS\Serializer\Annotation as JMS;
 use Symfony\Component\Validator\Constraints as Assert;
 use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
-use Base\AdminBundle\Traits\TenancyIdTrait;
-use Base\AdminBundle\Traits\TenancyIdTraitInterface;
+use Base\AdminBundle\Interfaces\PreRemoveInterface;
+use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
+use Sonata\AdminBundle\Exception\ModelManagerException;
 
 /**
  * @ORM\Entity
  * @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(name="unique_idx", columns={"name","tenancy_id"})})
- *
+ * @ORM\HasLifecycleCallbacks
  * @UniqueEntity(fields={"tenancyId","name"})
  */
 class Node implements TenancyIdTraitInterface, PreRemoveInterface
@@ -51,6 +53,11 @@ class Node implements TenancyIdTraitInterface, PreRemoveInterface
      */
     protected $childs;
 
+    /**
+     * @ORM\OneToMany(targetEntity="Cablemodem", mappedBy="node", fetch="EXTRA_LAZY")
+     */
+    protected $cablemodems;
+
 
     /**
      * Constructor
@@ -58,6 +65,7 @@ class Node implements TenancyIdTraitInterface, PreRemoveInterface
     public function __construct()
     {
         $this->childs = new ArrayCollection;
+        $this->cablemodems = new ArrayCollection;
     }
 
     /**
@@ -157,5 +165,35 @@ class Node implements TenancyIdTraitInterface, PreRemoveInterface
 
         return $entities;
     }
+    
+    /**
+     * @param Cablemodem $cablemodem
+     * @return Node
+     */
+    public function addCablemodem(Cablemodem $cablemodem)
+    {
+        $this->cablemodems[] = $cablemodem;
+
+        return $this;
+    }
+
+    /**
+     * @param Cablemodem $cablemodem
+     * @return Node
+     */
+    public function removeCablemodem(Cablemodem $cablemodem)
+    {
+        $this->cablemodems->removeElement($cablemodem);
+
+        return $this;
+    }
+
+    /**
+     * @return Doctrine\Common\Collections\Collection
+     */
+    public function getCablemodems()
+    {
+        return $this->cablemodems;
+    }
 
 }

+ 1 - 1
src/CablemodemBundle/Entity/Profile.php

@@ -348,7 +348,7 @@ class Profile  implements TenancyIdTraitInterface, PreRemoveBlockCascadeInterfac
     /**
      * @return array
      */
-    public function getEntitiesForRemove()
+    public function getEntitiesBlockRemove()
     {
         $entities = [];
         if ($this->cablemodems->count() != 0) {