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.

Easiest way to get model columns

Hello,

I have model Users. What is the easiest way to check if column exists in database users table? Is this the only way:

$columns = $this->getDI()->get('db')->describeColumns($this->getSource());
        foreach ($columns as $column)
            if ('deleted' == $column->getName())
            {
                if (empty($this->deleted))
                    $this->deleted = new \Phalcon\Db\RawValue('default');

                break;
            }


18.5k
Accepted
answer

I think doing raw SQL with SELECT column_name FROM information_schema.columns WHERE table_name = :tableName:. Then, you do a count($phql) != 0.