Answer the question
In order to leave comments, you need to log in
How to request a OneToMany field using Doctrine?
...
/**
* @ORM\OneToMany(targetEntity="App\Entity\ShiftBreak", mappedBy="shift")
*/
private $breaks;
...
...
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Shift", inversedBy="shifts")
* @ORM\JoinColumn(name="shift_id", referencedColumnName="id")
*/
private $shift;
...
$this->createQueryBuilder('s')
->select([
's.created',
's.name',
's.breaks'
])
->getQuery();
[Semantical Error] line 0, col 99 near 'breaks FROM App\Entity\Shift': Error: Invalid PathExpression. Must be a StateFieldPathExpression.
Answer the question
In order to leave comments, you need to log in
Your table (the "App\Entity\ShiftBreak" model) does not have the breaks field, so you cannot specify it in the select query.
To get data from 2 or more tables, you need to use JOIN:
$this->createQueryBuilder('s')
->select([
's.created',
's.name',
'b.id'
])
->join('s.breaks', 'b')
->getQuery();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question