T
T
test2018-07-12 17:19:20
symfony
test, 2018-07-12 17:19:20

Many-To-Many Symfony/Doctrine how to output data?

Let's say there is a product table and a pictures table. There is a many-to-many relationship between them. By means of the console, I created getters with setters. I figured out adding to the database. A table is created that correlates id. But I still don’t understand how to display it.
For example, a product with id = 1 includes images with id =2 and 3 ; How to get their path?

/**
     * @ORM\ManyToMany(targetEntity="Pictures", inversedBy="products")
     */
    private $pictures;

/////////////////////////////
    /**
     * @ORM\ManyToMany(targetEntity="Products", mappedBy="pictures")
     */
    private $products;

    /**
     * @var string
     *
     * @ORM\Column(name="path", type="string", length=255)
     */
    private $path;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GTRxShock, 2018-07-12
@HelmutKampfe

$pictureList = $product->getPictures();
foreach ($pictureList as $picture) {
    $picture->getPath();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question