Hi everyone,
I think I might have hit a bug in Phalcon with Criteria::fromInput and Model::columnMap.
I have a database table called "localized_languages" with fields "id", "language_id", "localized_language_id" and "name". In my controller I have the following code to search for localized languages:
$this->view->pick("localized-languages/search");
$numberPage = 1;
if ($this->request->isPost()) {
$query = Criteria::fromInput($this->di, 'My\Models\LocalizedLanguages', $this->request->getPost());
echo var_dump($query);
$this->persistent->searchParams = $query->getParams();
} else {
$numberPage = $this->request->getQuery("page", "int");
}
$parameters = array();
if ($this->persistent->searchParams) {
$parameters = $this->persistent->searchParams;
}
$localizedLanguages = LocalizedLanguages::find($parameters);
(...)
Now in my model I have the following column mappings:
public function columnMap()
{
return array(
'id' => 'id',
'language_id' => 'languageId',
'localization_language_id' => 'localizationLanguageId',
'name' => 'name'
);
}
If I execute this code, a var_dump of the $query object gives me the following:
object(Phalcon\Mvc\Model\Criteria)#138 (3) { ["_model":protected]=> string(34) "My\Models\LocalizedLanguages" ["_params":protected]=> NULL ["_hiddenParamNumber":protected]=> int(0) }
As a result, $parameters remains an empty array and I get back the complete list of "Localized Languages" instead of a list filtered by localizationLanguageId.
The following query is generated:
[Fri, 10 Oct 14 14:56:05 +0200][INFO] SELECT `localized_languages`.`id`, `localized_languages`.`language_id`, `localized_languages`.`localization_language_id`, `localized_languages`.`name` FROM `localized_languages`
BUT: if I comment the columnMap function and delete the metadata, then var_dump($query) gives me the following:
object(Phalcon\Mvc\Model\Criteria)#138 (3) { ["_model":protected]=> string(34) "My\Models\LocalizedLanguages" ["_params":protected]=> array(2) { ["conditions"]=> string(51) "localization_language_id=:localization_language_id:" ["bind"]=> array(1) { ["localization_language_id"]=> string(2) "39" } } ["_hiddenParamNumber":protected]=> int(0) }
Criteria now has parameters, so I get back the correct list. The following query is generated:
[Fri, 10 Oct 14 14:51:37 +0200][INFO] SELECT `localized_languages`.`id`, `localized_languages`.`language_id`, `localized_languages`.`localization_language_id`, `localized_languages`.`name` FROM `localized_languages` WHERE `localized_languages`.`localization_language_id` = :localization_language_id
Am I missing something very obvious here, or is this indeed a bug?