Hi,
I’ve got a query i’m running on one of modx’s core tables, i first constructed my query and tested in phpmyadmin on the database, and now i’m trying to convert it to work with the xPDO query function, i’m obviously doing something wrong as the query i see when i do prepare and toSQL isn’t right.
my query is:
SELECT DISTINCT price.contentid
FROM modx_site_tmplvar_contentvalues beds
JOIN modx_site_tmplvar_contentvalues price
ON price.tmplvarid = 3 AND price.value = "300-400"
JOIN modx_site_tmplvar_contentvalues location
ON location.tmplvarid = 5 AND location.value LIKE "%bletchley%"
WHERE beds.tmplvarid =1 AND beds.value >=2
on my modx database this returns 3 contentids that i would then use for getCollection etc...
i put this in my snippet:
$type = 3; //parent
$price = "300-400"; //price-range
$beds = 2; //number of beds
$location = "bletchley"; //location
$c = $modx->newQuery('modTemplateVarResource','Beds');
$c->join('modTemplateVarResource','Price');
$c->join('modTemplateVarResource','Location');
$c->where(array(
'Price.tmplvarid' => $type,
'Price.value' => "$price",
'Location.tmplvarid' => 5,
'Location.value:LIKE' => "%$location%",
'Beds.tmplvarid' => 1,
'Beds.value:>=' => $beds,
));
but what i get when i do:
$c->prepare();
$sql = $c->toSQL();
to test it, is this:
SELECT `modTemplateVarResource`.`id` AS `modTemplateVarResource_id`, `modTemplateVarResource`.`tmplvarid` AS `modTemplateVarResource_tmplvarid`, `modTemplateVarResource`.`contentid` AS `modTemplateVarResource_contentid`, `modTemplateVarResource`.`value` AS `modTemplateVarResource_value` FROM `modx_site_tmplvar_contentvalues` AS `modTemplateVarResource` JOIN `modx_site_tmplvar_contentvalues` `Price` ON JOIN `modx_site_tmplvar_contentvalues` `Location` ON WHERE ( AND ( `Price`.`tmplvarid` = '3' AND `Price`.`value` = '300-400' AND `Location`.`tmplvarid` = '5' AND `Location`.`value` LIKE '%bletchley%' AND `Beds`.`tmplvarid` = '1' AND `Beds`.`value` >= '2' ) )
how do i order the query in my snippet to join the way my SQL query works?