B
B
BonBon Slick2018-02-10 13:58:13
symfony
BonBon Slick, 2018-02-10 13:58:13

Which is more true ArrayCollection or Entity[]?

https://symfony.com/doc/current/doctrine/associati...
I saw how they wrote instead of ArrayCollection Entity[]

/**
* return Products[] // вместо ArrayColelction
*/
public function getProducts()
{
 return $this->products;
}

And yet, I would like to know, is it necessary to do initialization in the constructor?
/**
     * @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="category")
     */
    private $products;

    public function __construct()
    {
        $this->products = new ArrayCollection();
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-02-10
@BonBonSlick

And yet, I would like to know, is it necessary to do initialization in the constructor?

Yes, definitely, either in the constructor or in the addProduct method.
It's better to specify both options:
/**
* return ArrayColelction|Products[]
*/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question