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.

Model->Save() fails if field name is 'source'


In a table I have a column named 'source'.

Phalcon returns an error when I want to save a record in this table

my code:

                $params = array(
                    'ID'            => NULL,
                    'user_code'     => USER_CODE,
                    'source'        => $source,
                    'question'      => $question,
                    'true_answer'   => $trueAnswer,
                    'answers'       => $answers,
                    'date_added'    => $this->dateTime->getDate(),
                    'status'        => 'pending',
                    'score'         => 0

                if ($sugg->save($params) == true)

If I change the 'source' columns name everything get ok

sorry if my English is'nt very well ^-^


"source" is a reserved word in Phalcon models. Change it.

Is there anyway to use this name, such as alias name?


yes. You can use column mapping . But it's more easy and clean to just rename "source" in ... "question_source" for example.

Landing here because dealing with a legacy schema, changing the name is not a choice, will try the column mapping thing.