-
-
Save bolbo/0eea9640a5b29c5c8d38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param $where | |
* @return \PommProject\Foundation\ResultIterator | |
*/ | |
public function findWithModeleAndEquipements($where) | |
{ | |
$sql = <<<SQL | |
WITH equipement_detail AS ( | |
SELECT :projectionEquipement | |
FROM :vehiculeEquipement mfe | |
LEFT JOIN :equipement USING (equipement_id) | |
) | |
SELECT | |
:projection | |
FROM | |
:vehicule v | |
LEFT JOIN :marque ON v.marque_id = marque.id | |
LEFT JOIN equipement_detail USING (modele_id, finition_id) | |
WHERE :condition | |
GROUP BY v.vehicule_id, marque.* | |
SQL; | |
$projectionEquipement = $this | |
->getSession() | |
->getModel('\My\Component\Model\Project\ConfiguratorSchema\vehiculeEquipementModel') | |
->createProjection() | |
->setField('equipement_label', 'equipement.label', 'varchar') | |
; | |
$projection = $this->createProjection() | |
->setField('marque', 'marque', 'public.marque') | |
->setField('equipements', 'array_agg(equipement_detail)', 'configurator.modele_equipement[]'); | |
$sql = strtr($sql, | |
[ | |
':projection' => $projection->formatFieldsWithFieldAlias('v'), | |
':vehicule' => $this->getStructure()->getRelation(), | |
':marque' => $this | |
->getSession() | |
->getModel('\My\Component\Model\Project\PublicSchema\MarqueModel') | |
->getStructure() | |
->getRelation(), | |
':projectionEquipement' => $projectionEquipement->formatFieldsWithFieldAlias('mfe'), | |
':equipement' => $this | |
->getSession() | |
->getModel('\My\Component\Model\Project\ConfiguratorSchema\EquipementModel') | |
->getStructure() | |
->getRelation(), | |
':condition' => $where, | |
] | |
); | |
return $this->query($sql, $where->getValues(), $projection); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there any reason to use projections instead of raw sql? Do you have a lot of 'custom' fields in the model?