A
A
Alexander2016-11-13 16:57:46
symfony
Alexander, 2016-11-13 16:57:46

How to create a form so that the values ​​in the select are values ​​from the related (ManyToOne) entity?

there are two things related

class Cars
{
    /**
     * @var int
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\Price", mappedBy="car")
     */
    private $price;
}

and also related
class Price
{
    /**
     * @var int
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     *
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Cars", inversedBy="price")
     * @ORM\JoinColumn(name="car_alias", referencedColumnName="id")
     */
    private $car;
}

I want that when creating/editing the Price object it was possible to select from
the Cars objects created earlier
. I tried to use the EntityType field type, but it doesn’t seem to be very suitable.
Please tell me how to solve this issue
. My level is a Beginner, be understanding :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2016-11-13
@alexmixaylov

$builder->add('car');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question