2017-11-22 14 views
1

タイプをオフセット私は、エンティティリストにおける多対多の関係をしました:Doctrine2:警告:不正ISSETまたは空

どこかListingServiceで
/** 
* @ORM\Entity(repositoryClass="AppBundle\Repository\ListingRepository") 
* @ORM\Table(name="listings") 
*/ 
class Listing extends MainEntity 
{ 
    /** 
    * @ORM\Id 
    * @ORM\Column(type="uuid") 
    */ 
    private $id; 

    /** 
    * @ORM\ManyToMany(targetEntity="AppBundle\Entity\AttributeDescription", inversedBy="listings", cascade={"persist", "remove"}) 
    * @JoinTable(name="listing_attriubute_descriptions", 
    *  joinColumns={@JoinColumn(name="listing_id", referencedColumnName="id")}, 
    *  inverseJoinColumns={@JoinColumn(name="attribute_description_id", referencedColumnName="id")} 
    *  ) 
    */ 
    public $attributeDescriptions; 

    public function __construct() 
    { 
     $this->id = Uuid::uuid4(); 
     $this->attributeDescriptions = new ArrayCollection(); 
    } 

    public function removeAttributeDescription(AttributeDescription $attributeDescription) 
    { 
     if(!$this->attributeDescriptions->contains($attributeDescription)) 
     { 
      return; 
     } 
     $this->attributeDescriptions->remove($attributeDescription); 

     return $this; 
    } 
} 

私はこのようなリストのエンティティからのAttributeDescriptionを削除しようとしている:

$listing->removeAttributeDescription($toRemoveAttributeDescription); 

しかしエラーました:警告:私は(削除するために上陸しましたxdebugのを使用してISSETまたは空

に不正なオフセットタイプ)のArrayCollectionでの方法:

public function remove($key) 
{ 
    if (! isset($this->elements[$key]) && ! array_key_exists($key, $this->elements)) { 
     return null; 
    } 

    $removed = $this->elements[$key]; 
    unset($this->elements[$key]); 

    return $removed; 
} 

この問題は、isset($ this-> elements [$ key])に由来することがわかりました。ここ はxdebugのからのスクリーンショットです:あなたは$キーが含まれているのAttributeDescriptionを見ることができるように

enter image description here

、及びます$ this->要素AttributeDescriptionsの配列です。

私が何か間違っているのか、それとも教義のバグなのかは本当に分かりません。

私が使用しています:PHPとsymfonyの 3.3.13 7.1.1

ドクトリン:

"doctrine/doctrine-bundle": "^1.6", 
"doctrine/doctrine-cache-bundle": "^1.2", 
"doctrine/doctrine-migrations-bundle": "^1.2", 
"doctrine/orm": "^2.5" 

答えて

1

ソリューション:私は間違った方法を使用していたが。 remove()の代わりにremoveElement()を使用する必要があります

関連する問題