Я хочу сделать этот запрос на Symfony / Propel
SELECT
folders.NAME,
COUNT(documents.NAME),
COUNT(files.idfiles),
SUM(files.size)
FROM `folders`
LEFT JOIN `documents_has_folders` ON (documents_has_folders.folders_idfolders = folders.idfolders)
LEFT JOIN documents ON (documents_has_folders.DOCUMENTS_IDDOCUMENTS=documents.IDDOCUMENTS)
LEFT JOIN files ON (documents.IDDOCUMENTS=files.DOCUMENTS_IDDOCUMENTS)
GROUP BY folders.idfolders
Я делаю этот запрос
$x = FoldersQuery::create()
->addSelectColumn(FoldersPeer::NAME)
->addSelectColumn("COUNT(".DocumentsPeer::IDDOCUMENTS.")")
->addSelectColumn("COUNT(".FilesPeer::IDFILES.")")
->addSelectColumn("SUM(".FilesPeer::SIZE.")")
->addJoin(DocumentsHasFoldersPeer::FOLDERS_IDFOLDERS, FoldersPeer::IDFOLDERS, CRITERIA::LEFT_JOIN)
->addJoin(DocumentsHasFoldersPeer::DOCUMENTS_IDDOCUMENTS, DocumentsPeer::IDDOCUMENTS, CRITERIA::LEFT_JOIN)
->addJoin(DocumentsPeer::IDDOCUMENTS, FilesPeer::DOCUMENTS_IDDOCUMENTS, CRITERIA::LEFT_JOIN)
->addGroupByColumn(FoldersPeer::IDFOLDERS)
->find();
Возвращает:
500 | Internal Server Error | PropelException
Unable to execute SELECT statement [SELECT folders.NAME, COUNT(documents.IDDOCUMENTS), COUNT(files.IDFILES), SUM(files.SIZE) FROM LEFT JOIN folders ON (documents_has_folders.FOLDERS_IDFOLDERS=folders.IDFOLDERS) LEFT JOIN documents ON (documents_has_folders.DOCUMENTS_IDDOCUMENTS=documents.IDDOCUMENTS) LEFT JOIN files ON (documents.IDDOCUMENTS=files.DOCUMENTS_IDDOCUMENTS) WHERE folders.REMOVE_DATE IS NULL GROUP BY folders.IDFOLDERS] [wrapped: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN folders ON (documents_has_folders.FOLDERS_IDFOLDERS=folders.IDFOLDERS)' at line 1]
Почему на FROM нет таблицы ??? Почему это создает неправильный запрос?
Большое спасибо.
РЕДАКТИРОВАНИЕ:
Та же проблема, и если я делаю запрос, как это:
$c = new Criteria();
$c->addSelectColumn(FoldersPeer::NAME);
$c->addSelectColumn("COUNT(".DocumentsPeer::IDDOCUMENTS.")");
$c->addSelectColumn("COUNT(".FilesPeer::IDFILES.")");
$c->addSelectColumn("SUM(".FilesPeer::SIZE.")");
$c->addJoin(DocumentsHasFoldersPeer::FOLDERS_IDFOLDERS, FoldersPeer::IDFOLDERS, CRITERIA::LEFT_JOIN);
$c->addJoin(DocumentsHasFoldersPeer::DOCUMENTS_IDDOCUMENTS, DocumentsPeer::IDDOCUMENTS, CRITERIA::LEFT_JOIN);
$c->addJoin(DocumentsPeer::IDDOCUMENTS, FilesPeer::DOCUMENTS_IDDOCUMENTS, CRITERIA::LEFT_JOIN);
$c->addGroupByColumn(FoldersPeer::IDFOLDERS);
Опять после FROM нет таблицы ...
Unable to execute SELECT statement [SELECT folders.NAME, COUNT(documents.IDDOCUMENTS), COUNT(files.IDFILES), SUM(files.SIZE) FROM LEFT JOIN folders ON (documents_has_folders.FOLDERS_IDFOLDERS=folders.IDFOLDERS AND folders.remove_date IS NULL ) LEFT JOIN documents ON (documents_has_folders.DOCUMENTS_IDDOCUMENTS=documents.IDDOCUMENTS AND documents.remove_date IS NULL ) LEFT JOIN files ON (documents.IDDOCUMENTS=files.DOCUMENTS_IDDOCUMENTS AND documents.remove_date IS NULL AND files.remove_date IS NULL ) WHERE folders.remove_date IS NULL AND documents.remove_date IS NULL AND files.remove_date IS NULL GROUP BY folders.IDFOLDERS] [wrapped: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN folders ON (documents_has_folders.FOLDERS_IDFOLDERS=folders.IDFOLDERS ' at line 1]