FOSCommentBundle querybuilder добавить порядок сделать плохой запрос?

у меня есть что-то странное в FOSCommentBundle

в FOS \ CommentBundle \ Entity \ class CommentManager расширяет BaseCommentManager

метод:

public function findCommentsByThread(ThreadInterface $thread, $depth = null, $sorterAlias = null)

QueryBuilder:

$qb = $this->repository
->createQueryBuilder('c')
->join('c.thread', 't')
->where('t.id = :thread')
->orderBy('c.ancestors', 'ASC')
->setParameter('thread', $thread->getId());

if (null !== $depth && $depth >= 0) {
// Queries for an additional level so templates can determine
// if the final 'depth' layer has children.

$qb->andWhere('c.depth < :depth')
->setParameter('depth', $depth + 1);
}

$comments = $qb
->getQuery()
->execute();

print_array([$qb->getQuery()->getSQL(),$comments]);

я получил:

SELECT c0_.body AS body_0, c0_.ancestors AS ancestors_1, c0_.depth AS depth_2, c0_.created_at AS created_at_3, c0_.state AS state_4, c0_.id AS id_5, c0_.thread_id AS thread_id_6 FROM Comment c0_ INNER JOIN Thread t1_ ON c0_.thread_id = t1_.id WHERE t1_.id = ? ORDER BY c0_.ancestors ASC"

когда я отключаю заказ

$qb = $this->repository
->createQueryBuilder('c')
->join('c.thread', 't')
->where('t.id = :thread')
//->orderBy('c.ancestors', 'ASC')
->setParameter('thread', $thread->getId());

if (null !== $depth && $depth >= 0) {
// Queries for an additional level so templates can determine
// if the final 'depth' layer has children.

$qb->andWhere('c.depth < :depth')
->setParameter('depth', $depth + 1);
}

$comments = $qb
->getQuery()
->execute();

print_array([$qb->getQuery()->getSQL(),$comments]);

я получил:

SELECT c0_.body AS body_0, c0_.ancestors AS ancestors_1, c0_.depth AS depth_2, c0_.created_at AS created_at_3, c0_.state AS state_4, c0_.id AS id_5, c0_.score AS score_6, c0_.author_ip AS author_ip_7, c0_.author_name AS author_name_8, c0_.plus AS plus_9, c0_.minus AS minus_10, c0_.thread_id AS thread_id_11, c0_.author_id AS author_id_12 FROM Comment c0_ INNER JOIN Thread t1_ ON c0_.thread_id = t1_.id WHERE t1_.id = ?

вот сущность:

<?php

namespace Place\PlaceBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use FOS\CommentBundle\Entity\Comment as BaseComment;
use FOS\CommentBundle\Model\VotableCommentInterface;
use FOS\CommentBundle\Model\SignedCommentInterface;
use Symfony\Component\Security\Core\User\UserInterface;

/**
* @ORM\Entity
* @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
*/
class Comment extends BaseComment implements SignedCommentInterface, VotableCommentInterface
{

/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;

/**
* Thread of this comment
*
* @var Thread
* @ORM\ManyToOne(targetEntity="Thread", cascade={"persist"})
*/
protected $thread;

/**
* @ORM\Column(type="integer")
* @var int
*/
protected $score = 0;

/**
* Author of the comment
*
* @ORM\ManyToOne(targetEntity="Mea\ContactBundle\Entity\Contact")
* @var User
*/
protected $author;

/**
* @ORM\Column(type="string",nullable=true)
* @var
*/
protected $author_ip;

/**
* @ORM\Column(type="string",nullable=true)
* @var
*/
protected $author_name;

/**
* @var string
*/
protected $author_email;


/**
* @ORM\Column(type="integer")
* @var int
*/
protected $plus=0;

/**
* @ORM\Column(type="integer")
* @var int
*/
protected $minus=0;


/**
* @return mixed
*/
public function getPlus()
{
return $this->plus;
}


public function incrementPlus()
{
$this->plus += 1;
}

/**
* @return mixed
*/
public function getMinus()
{
return $this->minus;
}


public function incrementMinus()
{
$this->minus += 1;
}


public function setAuthor(UserInterface $author)
{
$this->author = $author;
}

public function getAuthor()
{
return $this->author;
}

public function getAuthorName()
{
if (null === $this->getAuthor()) {
if($this->author_name)
return $this->author_name;
else
return 'Gość';
}

return $this->getAuthor()->getUsername();
}


/**
* Sets the score of the comment.
*
* @param integer $score
*/
public function setScore($score)
{
$this->score = $score;
}

/**
* Returns the current score of the comment.
*
* @return integer
*/
public function getScore()
{
return $this->score;
}

/**
* Increments the comment score by the provided
* value.
*
* @param integer value
*
* @return integer The new comment score
*/
public function incrementScore($by = 1)
{
if($by>0)
$this->incrementPlus();
else $this->incrementMinus();

$this->score += $by;
}

/**
* @return mixed
*/
public function getAuthorIp()
{
return $this->author_ip;
}

/**
* @param mixed $author_ip
*/
public function setAuthorIp($author_ip)
{
$this->author_ip = $author_ip;
}

/**
* @param mixed $author_name
*/
public function setAuthorName($author_name)
{
$this->author_name = $author_name;
}

/**
* @return string
*/
public function getAuthorEmail()
{
return $this->author_email;
}

/**
* @param string $author_email
*/
public function setAuthorEmail($author_email)
{
$this->author_email = $author_email;
}

/**
* @param mixed $plus
*/
public function setPlus($plus)
{
$this->plus = $plus;
}

/**
* @param mixed $minus
*/
public function setMinus($minus)
{
$this->minus = $minus;
}

}

Кто-нибудь понимает, зачем добавлять порядок создания запроса без всех полей?

2

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]