Hey,

I've two Entities mapped to eachother. With native SQL I'd do something 
like this:

SELECT * FROM Element e LEFT JOIN Statistics s ON s.element_local_id = e.id;

And it would give me all records from `Element`, even if there're no 
matching records in `Statistics`, but they'd be NULL.
If I am using QueryBuilder with leftJoin function, I won't get any 
non-matching records.

I am using OneToMany/ManyToOne, because there's a column "date" in 
`Statistics`, so they're multiple rows in `Statistics` matching one 
`Element`.

Looking forward to helpful answer.

BR
Ramon

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

    /**
     * @var Statistics
     *
     * @ORM\OneToMany(targetEntity="Statistics", mappedBy="element")
     * @ORM\JoinColumn(name="id", referencedColumnName="element_local_id", 
nullable=true)
     */
    private $statistics;
}

class Statistics
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
    
    /**
     * @var Element
     *
     * @ORM\ManyToOne(targetEntity="Element", inversedBy="statistics")
     * @ORM\JoinColumn(name="element_local_id", referencedColumnName="id", 
onDelete="CASCADE")
     */
    private $element;
}

class ElementRepository extends EntityRepository
{
    public function getStatistics() {        
        $query = $this
            ->createQueryBuilder('e')
            ->leftJoin('e.statistics', 's');
        
        return $query->getQuery()->getArrayResult();
    }
}

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to