ich habe diese Abfrage in MySQL und ich will in Lehre anwendenSymfony - Lehre createQueryBuilder mehrere Joins
SELECT * FROM ads_list AS al LEFT JOIN (ads_category AS ac, ads_category_main AS acm) ON (ac.id = al.category_id AND ac.parent_cat_id = acm.id)
Sie haben keine Ahnung, wie diese mit Lehre zu benutzen? ich dies in einem Repository Parameter verwendet bin geht auszuwählen ads_category_main
so die ads_list
mit category
ich versuche, und jede Kategorie eine parent hat die
ads_category_main
SQL gespeichert
CREATE TABLE `ads_list` (
`id` int(11) NOT NULL,
`category_id` int(11) DEFAULT NULL,
`title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`content` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
`posted_at` date NOT NULL,
`post_xpr` date NOT NULL,
`agency_id` int(11) DEFAULT NULL,
`slug` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `ads_category` (
`id` int(11) NOT NULL,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`parent_cat_id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `ads_category_main` (
`id` int(11) NOT NULL,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
so weit habe ich
public function findAllP($main)
{
return $this->createQueryBuilder('pl')
->leftJoin('pl.category', 'al')
->where('al.parentCat = :pc')
->setParameter('pc', $main)
->getQuery()
->execute();
}
und wie verwende ich die Ausgangsdaten in einem Controller?
Sie haben ein Beispiel in der Dokumentation: http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/query-builder.html#building-expressions – duncan
Versuchen 'getResult()' anstelle von 'execute()' –