I searched a while, but until now, I wasn't able to find a suitable answer.
In my "Offer" class, I have the following:
/**
* @ORM\OneToMany(mappedBy="offer")
* @var Collection<OfferItem>
*/
protected $offerItems;
/**
* @return Collection
*/
public function getOfferItems()
{
return $this->offerItems;
}
/**
* @param Collection $offerItems
*/
public function setOfferItems($offerItems)
{
$this->offerItems = $offerItems;
}
Now, I create a new Offer and would like to add some OfferItems as well:
$offer = new Offer();
$offerItem = new OfferItem();
$offer->getOfferItems()->add($offerItem);
But then, the error comes: "Fatal error: Call to a member function add() on null". Okay, in some points, it makes sense - the collection is empty until know - and perhaps "null". I'm not such an PHP / Flow3 / Doctrine expert, to have the overview, how to handle such an sitation? I think, I have to set an empty (but not null-) collection to the offer. But
$collection = new \Doctrine\Common\Collections\Collection()
Is not working, because "Collection" is an interface.
Any hint, idea or something like that, to understand my problem would be nice.
Thank you very much in advance for your help!