sql - Doctrine include null on join -
i trying create query fetch every users, and, have received feedback, fetch rating average well.
after research, have crafted query return users have received feedback , respective rating. start. don't users no feedback when add ->leftjoin('appfeedbackbundle:feedback', 'f', 'with', 'u.id = f.user')
$qb = $this->createquerybuilder('u') ->select(array( 'u', 'avg(r.ratings)' )) ->orderby('u.lastlogin', 'desc') ->setmaxresults($limit) ->leftjoin('appfeedbackbundle:feedback', 'f', 'with', 'u.id = f.user') ->join('f.rating', 'r') ->groupby('u.id');
do know how both users , without feedbacks, , associate said feedback have one?
remark
i avoid reversing manytoone relationship (feedback <-> user) in user entity because tend fetch users time , feel end having lots of feedbacks, hence don't want have every time users, performance reasons (please tell me if don't think performance argument relevant or think not matter much).
note
the links between feedbacks, users , ratings in feedback entity, such:
/** * @orm\manytoone(targetentity="app\userbundle\entity\user", cascade={"persist", "remove"}) */ private $user; /** * @orm\onetoone(targetentity="app\feedbackbundle\entity\rating", cascade={"persist", "remove"}) * @assert\valid() */ private $rating;
left join rating users have feedback have rating not ones without feedback.
Comments
Post a Comment