Doubts in the creation of the relationship

1

Personal I have 2 classes, one call Venda and another ItensVenda . I need to create a relationship for:

  • When I open a sale, I can see all the items in this sale.

  • When I access an item from a sale I can see the data from the Sale.

  • How do I create these relationships in Doctrine?

    Class Venda : id , nome , data

    Class ItensVenda : id , nome , valor

    Thank you.

        
    asked by anonymous 05.03.2015 / 01:34

    1 answer

    0

    Make a OneToMany relationship.

    Class Venda :

    /**
     * @ORM\Entity
     * @ORM\Table(name="Venda")
     */
    class Venda
    {
        /**
         * @ORM\Column(type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue
         */
        protected $id;
    
        /**
         * @ORM\OneToMany(targetEntity="ItensVenda", mappedBy="venda", cascade={"remove"})
         */
        protected $itensVenda;
    
        /** demais atributos**/
    }
    

    Class ItensVenda :

    /**
     * @ORM\Entity
     * @ORM\Table(name="ItensVenda")
     */
    class ItensVenda
    {
        /**
         * @ORM\Column(type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue
         */
        protected $id;
    
        /**
         * @ORM\ManyToOne(targetEntity="Venda", inversedBy="itensVenda")
         * @ORM\JoinColumn(name="venda_id", referencedColumnName="id", nullable=FALSE)
         */
        protected $venda;
    
        /** demais atributos**/
    }
    

    Source >

        
    05.03.2015 / 03:19