You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to filter one collection (Doctrine\Common\Collections\ArrayCollection) which is generated as result of a OneToMany Relation only works the first orderBy, but not the others:
// Some comments here
/****
* Event
*
* @ORM\Table(name="agenda*_date*possible")
* @ORM\Entity(repositoryClass="App\AgendaBundle\Entity\PossibleDateRepository")
*/
class PossibleDate
{
/****
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/****
* @var \DateTime
*
* @ORM\Column(name="startDate", type="datetime")
*/
private $startDate;
/****
*
* @var collection
*
* @ORM\ManyToOne(targetEntity="App\AgendaBundle\Entity\ProposedEvent", inversedBy="possibleDates")
* @ORM\JoinColumn(name="proposed*event*id", nullable=false)
****/
protected $proposedEvent;
/****
* @var integer
*
* @ORM\Column(name="number*of*votes", type="integer")
*/
private $numberOfVotes;
/****
* Set startDate
*
* @param \DateTime $startDate
* @return Event
*/
public function setStartDate($startDate)
{
$this->startDate = $startDate;
return $this;
}
/****
* Get startDate
*
* @return \DateTime
*/
public function getStartDate()
{
return $this->startDate;
}
/****
* Set votes
*
* @param integer $votes
* @return Event
*/
public function setNumberOfVotes($numberOfVotes)
{
$this->numberOfVotes = $numberOfVotes;
return $this;
}
/****
* Get votes
*
* @return integer
*/
public function getNumberOfVotes()
{
return $this->numberOfVotes;
}
// Some comments here
/****
* Event
*
* @ORM\Table(name="agenda**event")
* @ORM\Entity(repositoryClass="App\AgendaBundle\Entity\ProposedEventRepository")
*/
class ProposedEvent
{
/****
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/****
*
* @var collection
*
* @ORM\OneToMany(targetEntity="App\AgendaBundle\Entity\PossibleDate", mappedBy="proposedEvent", cascade={"persist"})
****/
protected $possibleDates;
/****
* Constructor
*/
public function **construct()
{
$this->possibleDates = new ArrayCollection();
}
/****
* Add possibleDate
*
* @param \App\AgendaBundle\Entity\PossibleDate $possibleDate
* @return ProposedEvent
*/
public function addPossibleDate(\App\AgendaBundle\Entity\PossibleDate $possibleDate)
{
$this->possibleDates[] = $possibleDate;
$possibleDate->setProposedEvent($this);
return $this;
}
/****
* Remove possibleDate
*
* @param \App\AgendaBundle\Entity\PossibleDate $possibleDate
*/
public function removePossibleDate(\App\AgendaBundle\Entity\PossibleDate $possibleDate)
{
$this->possibleDates->removeElement($possibleDate);
}
/****
* Get possibleDates
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getPossibleDates()
{
return $this->possibleDates;
}
public function getSelectedDate()
{
//TODO: Correct Date (Second ordering criteria not working)
$criteria = Criteria::create()
->where(Criteria::expr()->gt("startDate", new \DateTime()))
->orderBy(array("numberOfVotes" => Criteria::DESC, "startDate"=>Criteria::ASC))
->setFirstResult(0)
->setMaxResults(1);
$selectedDates = $this->getPossibleDates()->matching($criteria);
return $selectedDates[0];
}
When I use the getSelectedDate() in a environment with more than one PossibleDate with the max numberOfVotes possible, the function returns a random of the PossibleDates wich have the maximum number of votes, but not taking in account the startDate ordering criteria.
There is no query to database because the getSelectedDate() is called with the array collection loaded.
The text was updated successfully, but these errors were encountered:
Jira issue originally created by user hisie:
When trying to filter one collection (Doctrine\Common\Collections\ArrayCollection) which is generated as result of a OneToMany Relation only works the first orderBy, but not the others:
When I use the getSelectedDate() in a environment with more than one PossibleDate with the max numberOfVotes possible, the function returns a random of the PossibleDates wich have the maximum number of votes, but not taking in account the startDate ordering criteria.
There is no query to database because the getSelectedDate() is called with the array collection loaded.
The text was updated successfully, but these errors were encountered: