A
A
Alexander2016-12-05 11:54:19
symfony
Alexander, 2016-12-05 11:54:19

How can such functionality be implemented?

There are two entities Book - booking
and Extra - additional services
when a person books a taxi, he can choose additional services
for example
Meet with a sign: 5 dollars
Grab a sandwich: 10 dollars :)
Carry bags: 50 dollars
you can connect several services to one booking
in the form this case should look like how a person sees the name of the service and the price of the Extra list with checkboxes
- marks the checkbox and thus attaches the additional service to the booking
how can this functionality be implemented correctly? I struggle for a few days, I
tried
/**
* Many Book have Many Extra.
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Extra")
* @ORM\JoinTable(name="book_extra",
* joinColumns={@ORM\JoinColumn(name="book_id", referencedColumnName="id")} ,
* inverseJoinColumns={@ORM\JoinColumn(name="extra_id", referencedColumnName="id")}
* )
*/
does not work or you need to create an intermediate entity manually

/**
 * Book
 *
 * @ORM\Table(name="book")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\BookRepository")
 */
class Book
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Extra")
     */

    private $extras;


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

/**
 * Extra
 *
 * @ORM\Table(name="extra")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\ExtraRepository")
 */
class Extra
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

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


    /**
     * @var int
     *
     * @ORM\Column(name="summ", type="integer")
     */
    private $summ;

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question