Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

columnMap problem.


I had a little problem trying to use a for loop with a model with columnMap set and I really don't know if my solution is the best way to deal with this situation.

I have a table containing the users from my system, but i don't actually need all the columns to do this task. So I defined the following column Map:

public function columnMap(){
        return array (
            'id' => 'id',
            'cell_phone' => 'cell_phone',
            'verified' => 'verified'

When I try to get some elements using the find method and iterate I receive an error message saying 'The column 'name' doesn't make part of the column map'.

To fix this error, I was forced to specify the columns in the find method as bellow:

$this->users = Users::find(array(
            'conditions' => $this->config->project->sendCondition,
            'columns' => 'id, cell_phone, verified',
            'limit' => 100

Is this the expected behavior ?

I am not saying this is a bug, but is strange.

Thank you.


i guess this is default. However i think you shoudl be able to declare this in your model

public static function find($parameters = null){

        if (false === is_array($parameters)){
            $parameters = [];

        if (false === isset($parameters['columns'])){
            $parameters['columns'] = "whatever";

        return parent::find($parameters);

i didnt test it but it should be doable

Yes, this is expected behaviour beacause you have name column returned from database. Im not sure but whatabout:

public function columnMap(){
        return array (
            'id' => 'id',
            'cell_phone' => 'cell_phone',
            'verified' => 'verified',
            'name' => ''

never checked it though



Thank you for the answers. I will try both soon.

Another point is that the model class only has the id, cell_phone and verified atributes declared.