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

How to get model attribute name which has default value ?

Is there any way to get model attribute name which has default value?

Based on example below, I would like to have level & permission.

CREATE TABLE sis_window
(   id VARCHAR NOT NULL PRIMARY KEY,
    name VARCHAR NOT NULL,
    level INT NOT NULL DEFAULT 0,
    permission INT NOT NULL DEFAULT 0
);

Do you want to know what that default value is in your PHP code? Or are you retrieving a record? If the latter, the default value should be there if nothing else was provided for those fields. If the former, I don't think Phalcon has any way of determining the default value for a column in the DB.



7.2k

Neither. I just want to get attribute name which has default value from a table.

Something similar on how we get attribute name which is not null:

notNullAttributes = $this->getModelsMetaData()->getNotNullAttributes($this);    //this will return id, name, level & permission because these are not null attribute