0
votes

I want to create own custom meta-data parser for Phalcon models (as current hasn't annotations for indexes and mapping one column to another parameter). Unfortunately, when I am returning mapping as array:

/**
 * @param \Phalcon\Mvc\ModelInterface $model
 * @param \Phalcon\DiInterface $di
 * @return array
 */
public function getColumnMaps($model, $di)
{
    $columns = [];

    /** @var \Phalcon\Annotations\Reflection $reflection */
    $reflection = $di->get('annotations')->get($model);

    foreach ($reflection->getPropertiesAnnotations() as $name => $collection) {
        if ($collection->has('Column')) {
            $columns[$collection->get('Column')->getNamedArgument('column') ?: $name] = $name;
        }
    }

    return $columns;
}

As I found, Phalcon\Mvc\Model\MetaData\Strategy\Annotations in that method returns null. My result is like array of ID_IN_TABLE => PARAMETER_NAME, eg. 'referer_id' => 'refererId' which map field from database with underscore with camel-case field from model. It throws errors Notice: Undefined index: 0 and Notice: Undefined index: 1 when I am trying to use find, count or findFirst method, e.g.:

Users::find([
    implode(' AND ', $conditions),
    'bind' => $bind,
    'limit' => $this->getLimit(),
    'offset' => $this->getLimit() * ($this->getPage() - 1)
])

What am I doing wrong?

Thanks in advance, David.

1

1 Answers

0
votes

The return value of getColumnMaps() is supposed to look like this:

array(
    0 => $ordered_column_map,
    1 => $reverse_column_map
);

where $ordered_column_map is ID_IN_TABLE => PARAMETER_NAME amd $reverse_column_map is array_flip($ordered_column_map).