Hello,
i got table in PostgreSQL, where column "active" is required (NOT NULL) but it has default value (true) specified in database.
Table definition:
CREATE TABLE ino_admin
(
id serial NOT NULL,
login_name character varying(128) NOT NULL,
login_password character varying(128) NOT NULL,
public_name character varying(128) NOT NULL,
creation_time timestamp without time zone NOT NULL,
last_login_time timestamp without time zone,
active boolean NOT NULL DEFAULT true,
CONSTRAINT ino_admin_pkey PRIMARY KEY (id),
CONSTRAINT ino_admin_login_name_key UNIQUE (login_name)
)
WITH (
OIDS=FALSE
);
When i try to create/save model record with "active" variable value set to NULL, im getting message "active is required".
$inoAdmin->login_name = 'admin';
$inoAdmin->public_name = 'Default administrator';
$inoAdmin->creation_time = date('Y-m-d H:i:s');
$inoAdmin->login_password = password_hash( $adminPassword , \PASSWORD_BCRYPT );
if (!$inoAdmin->create()) {
foreach ($inoAdmin->getMessages() as $message) {
$flashSession->error($message);
}
}
I know i can do it like that:
$inoAdmin->active = new \Phalcon\Db\RawValue('default');
And it is working... but... maybe it would be better if ORM engine could recognise it and allow creating record without column which has defult value on DB side, the same for updating: allow NULL value?