Please validate your mappings using the console command `orm:validate-schema` 
and fix the errors it displays.
For example, theĀ @ORM\JoinColumn on Element::$statistics shouldn't be there, 
the mapping is fully defined on Statistics::$element.

Note the following behavior:

When using the defaultĀ ("object") hydration mode, the query will return an 
array of Element entities (PHP objects). If for a specific Element there are no 
matching Statistics entities, the Collection $statistics will be empty.

When using the "array" hydration mode, the behavior is similar: You'll get an 
array of Element arrays. Those Element arrays contain property/value pairs. If 
for a specific Element there are no matching Statistics, the 'statistics' key 
will be empty or missing (not sure without looking it up).
So you'll always get a nested array as return value, never a row-by-row array 
like a plain SQL query would return.

The closest you can get to a row-by-row result is using the "scalar" hydration 
mode.

--  
Jasper N. Brouwer
(@jaspernbrouwer)


On 24 November 2014 at 14:22:11, Ramon ([email protected]) wrote:
> 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