It seems i found another solution - the easiest way is
$query->where("price.value >= 6000");
and best way to combine with okyanet solution
$query->where("CAST(price.value AS UNSIGNED INTEGER) >= 6000");
All of them works correct in xPDO
Question
$query = $this->modx->newQuery('modResource');
$query->leftJoin('modTemplateVarResource', "price", array("modResource.id = price.contentid", "price.tmplvarid = 2"));
$query->where(array("price:>=" => 6000));
$query->prepare();
echo $query->toSql();
RETURNS:
`modResource`.`context_key` AS `modResource_context_key`, `modResource`.`content_type` AS `modResource_content_type`, `modResource`.`uri` AS `modResource_uri`, `modResource`.`uri_override` AS `modResource_uri_override`, `modResource`.`hide_children_in_tree` AS `modResource_hide_children_in_tree`, `modResource`.`show_in_tree` AS `modResource_show_in_tree`, `modResource`.`properties` AS `modResource_properties`
FROM `modx_site_content` AS `modResource`
LEFT JOIN `modx_site_tmplvar_contentvalues` `price`
ON ( modResource.id = price.contentid
AND price.tmplvarid = 2 )
WHERE `modResource`.`price` >= '6000'
Why is integer quoted? It should be treated as an int.
Solution 2
It seems i found another solution - the easiest way is
$query->where("price.value >= 6000");
and best way to combine with okyanet solution
$query->where("CAST(price.value AS UNSIGNED INTEGER) >= 6000");
All of them works correct in xPDO
OTHER TIPS
This is probably not working because "price" is the table alias used on the join; you need to run your where condition against an actual field - price.value
:
$query = $this->modx->newQuery('modResource');
$query->leftJoin('modTemplateVarResource', "price", array("modResource.id = price.contentid", "price.tmplvarid = 2"));
$query->where(array("price.value:>=" => 6000));
$query->prepare();
echo $query->toSql();
I'm almost 100% certain the where condition will work in this case, even as a string. However if you're still running into problems you might try casting "price.value" as an integer (not tested):
$query = $this->modx->newQuery('modResource');
$query->leftJoin('modTemplateVarResource', "price", array("modResource.id = price.contentid", "price.tmplvarid = 2"));
$query->where(array("CAST(price.value AS UNSIGNED INTEGER):>=" => 6000));
$query->prepare();
echo $query->toSql();
PS. float/decimal would usually be a more appropriate type for price, but that's up to you ;)
the right way for me is to use
$whereArray = array('CAST(:price.value:as unsigned)>=' => 6000);
//then put it to
$query->where($whereArray);