Skip to content

Instantly share code, notes, and snippets.

@kaworu
Created March 5, 2015 19:29
Show Gist options
  • Save kaworu/25ff1c0879db363ba167 to your computer and use it in GitHub Desktop.
Save kaworu/25ff1c0879db363ba167 to your computer and use it in GitHub Desktop.
/**
* filter only the bookings for the given date.
* @see http://doctrine-orm.readthedocs.org/en/latest/reference/working-with-associations.html#filtering-collections
*/
public function getBookingsOn(\DateTime $date)
{
$the_day = new \DateTime($date->format('Y-m-d'));
$the_day_after = $the_day->add(new \DateInterval('P1D'));
$critera = Critera::create()
->where(Critera::expr()->gte('startAt', $the_day))
->andWhere(Critera::expr()->lt('startAt', $the_day_after))
->orderBy(['startAt' => Criteria::ASC]);
$bookings = $this->getBookings()->matching($critera);
return $bookings;
}
@kaworu
Copy link
Author

kaworu commented Mar 5, 2015

SELECT * FROM bookings
INNER JOIN rooms ON rooms.id = bookings.room_id
WHERE DATE(bookings.start_at) = DATE(:date)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment