Phalcon version 1.3.4
This returns correct results:
SELECT a.* FROM [Modules\Engine\Models\Artists\Artist] AS [a] WHERE a.location = :location:
This returns scanning error:
SELECT a.* FROM [Modules\Engine\Models\Artists\Artists] AS [a] INNER JOIN [Modules\Engine\Models\PerformancesDates ] AS [pd ] ON a.id = pd.owner_id WHERE pd.date = :date:
Scanning error before 'Modules\Engine\M...' when parsing: SELECT a.* FROM [Modules\Engine\Models\Artists\Artists] AS [a] INNER JOIN [Modules\Engine\Models\PerformancesDates ] AS [pd ] ON a.id = pd.owner_id WHERE pd.date = :date: (170)
This returns scanning error too:
SELECT a.* FROM [Modules\Engine\Models\Artists\Artists] AS [a] INNER JOIN [Modules\Engine\Models\PerformancesDates ] AS [pd ] ON a.id = pd.owner_id WHERE (a.location = :location:) AND (pd.date = :date:)
Scanning error before 'Modules\Engine\M...' when parsing: SELECT a.* FROM [Modules\Engine\Models\Artists\Artists] AS [a] INNER JOIN [Modules\Engine\Models\PerformancesDates ] AS [pd ] ON a.id = pd.owner_id WHERE (a.location = :location:) AND (pd.date = :date:) (202)
Here is the method:
public function explore($location, $date)
{
$builder = $this->getDi()->getModelsManager()->createBuilder();
$builder->columns('a.*')
->addFrom('Modules\Engine\Models\Artists\Artists', 'a');
if (!empty($date) && !empty($location)) {
$builder->innerJoin('Modules\Engine\Models\PerformancesDates ', 'a.id = pd.owner_id', 'pd ')
->andWhere('a.location = :location:', array('location' => $location))
->andWhere('pd.date = :date:', array('date' => $date));
} elseif (!empty($date) && empty($location)) {
$builder->innerJoin('Modules\Engine\Models\PerformancesDates ', 'a.id = pd.owner_id', 'pd ')
->andWhere('pd.date = :date:', array('date' => $date));
} elseif (!empty($location) && empty($date)) {
$builder->andWhere('a.location = :location:', array('location' => $location));
}
print_r($builder->getPhql());
die();
}