We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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;
            }


33.8k
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.