SELECT COUNT(c.id) CountOfComments
FROM comments
WHERE c.record_id IN (... IDS ...)
GROUP BY c.record_id
В IN просто перечисляете ID записей, полученных из 1-го запроса.class SomeClass
{
...
private function getErrorCodes() {
$query = "SELECT"
. "`code` "
. "FROM "
. "`table` "
. "WHERE ...";
return DB->fetch_column($query);
}
...
}
$keeper = new FileDataKeeper();
$someService->setDataKeeper($keeper);
// or
$keeper = new MysqlDataKeeper();
$someService->setDataKeeper($keeper);
class SomeService
{
// ...
public function setDataKeeper(DataKeeper $keeper)
{
// ...
}
// ...
}
// somewhere in controller
private function getEntityManager()
{
return \Registry::getInstance()->get('em');
}
/**
* @return \App\Repository\UserRepository
*/
private function getUserRepository()
{
return $getEntityManager()->getRepository('App\Entity\User');
}
http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=habrahabr&start=10