我试图用symfony1.4中的条令1运行以下查询,但是它说 Couldn't find class (SELECT
有500个内部错误。我有没有办法让它和教义一起工作:
SELECT location_id FROM
(SELECT DISTINCT location_id FROM location_feature_restriction WHERE feature_restriction_id IN(4,15,16)) as t1
WHERE location_id
NOT IN(SELECT DISTINCT location_id FROM location_feature_restriction WHERE feature_restriction_id = 5);
目前,我有这样的,但它不工作:
/**
* Search for venues with selected features
* @param Doctrine_Query $qry The SQL query
* @param array $values The form values
*/
protected function addSearchFeatures(Doctrine_Query $qry, array $values = array()) {
// "Dry" and "Bespoke Hire" options
$qryParams = array();
$qryParts = array();
if (in_array("bespoke_hire", $values["features"]) && $values["features"][array_search("bespoke_hire", $values["features"])]) {
$qryParts[] = "q.bespoke_hire = :BESPOKE_HIRE";
$qryParams["BESPOKE_HIRE"] = 1;
unset($values["features"][array_search("bespoke_hire", $values["features"])]);
}
if (array_key_exists("dry_hire", $values["features"]) && $values["features"][array_search("dry_hire", $values["features"])]) {
$qryParts[] = "q.dry_hire = :DRY_HIRE";
$qryParams["DRY_HIRE"] = 1;
$values["features"][array_search("dry_hire", $values["features"])];
}
if (count($qryParts)) {
$qry->andWhere(implode(" OR ", $qryParts), $qryParams);
}
// Search for selected features
if (count($values["features"])) {
// If anyone need to features should be searched using the OR condition then comment having condtion from following line.
if ($values["no_noise_restrictions"]) {
$subSql = "SELECT location_id FROM
(SELECT DISTINCT location_id FROM LocationFeatureRestriction WHERE feature_restriction_id IN(".implode(',', $values["features"]).")) as t1
WHERE location_id
NOT IN(SELECT DISTINCT location_id FROM LocationFeatureRestriction WHERE feature_restriction_id = 5)";
} else {
$subSql = "SELECT LocationFeatureRestriction.location_id
FROM LocationFeatureRestriction
WHERE feature_restriction_id IN(".implode(',', $values["features"]).")
GROUP BY location_id
HAVING COUNT(DISTINCT feature_restriction_id) = ".count($values['features']);
}
$qry->andWhere('q.id IN ('.$subSql.')');
}
}
条令错误:
更新:
我已将查询简化为以下内容,但它给出了错误 Couldn't get short alias for
:
SELECT DISTINCT location_id FROM location_feature_restriction
WHERE location_id NOT IN
(SELECT DISTINCT location_id FROM location_feature_restriction
WHERE feature_restriction_id = 5);
然后继续为表添加别名,但现在它给出了错误 Couldn't find class featureTable
:
SELECT DISTINCT location_id FROM location_feature_restriction
WHERE location_id NOT IN
(SELECT DISTINCT location_id FROM location_feature_restriction AS featureTable
WHERE featureTable.feature_restriction_id = 5);
1条答案
按热度按时间nfs0ujit1#
真正值得称赞的是@kris peeling,因为他让我注意到了这个想法!
好像我只是需要一个id的数组所以我用了
Doctrine_Manager (PDO)
去做这项工作。以下是我为完成任务所做的: