You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue: If I insert a new user into my database, DEFAULT values set in MySQL is ignored and value is set to NULL.
Environment:
PHP 7.1.8
mysql Ver 14.14 Distrib 5.7.19, for osx10.13 (x86_64) using EditLine wrapper
anax/database v1.1.4
Following test example was used in SQL:
`
DROP TABLE IF EXISTS User;
CREATE TABLE User ( id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL, username VARCHAR(80) UNIQUE NOT NULL, mail VARCHAR(100) UNIQUE NOT NULL, password VARCHAR(255) NOT NULL, admin INTEGER DEFAULT 0, created DATETIME, updated DATETIME, deleted DATETIME, active DATETIME
) ENGINE INNODB CHARACTER SET utf8 COLLATE utf8_swedish_ci;
`
The text was updated successfully, but these errors were encountered:
To solve this the ActiveRecord must be updated to only save those properties that has changed. Currently all properties are saved, independent on its been updated or not.
After extensive testing, we noticed that if the value is not defined within the class declaration then the default value from the SQL is used. So with the above testing (created TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP) and the following class ->
/**
* Columns in the table.
*
* @var integer $idComment primary key auto incremented.
* @var integer $idQuestion not null.
* @var string $mail not null.
* @var string $title not null.
* @var string $post not null.
*/
public $idComment;
public $idQuestion;
public $mail;
public $post;`
the class will use the DEFAULT value. This might be a good way to do it but documentation should be done on how to handle DEFAULT values.
Issue: If I insert a new user into my database, DEFAULT values set in MySQL is ignored and value is set to NULL.
Environment:
PHP 7.1.8
mysql Ver 14.14 Distrib 5.7.19, for osx10.13 (x86_64) using EditLine wrapper
anax/database v1.1.4
Following test example was used in SQL:
`
DROP TABLE IF EXISTS User;
CREATE TABLE User (
id
INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,username
VARCHAR(80) UNIQUE NOT NULL,mail
VARCHAR(100) UNIQUE NOT NULL,password
VARCHAR(255) NOT NULL,admin
INTEGER DEFAULT 0,created
DATETIME,updated
DATETIME,deleted
DATETIME,active
DATETIME) ENGINE INNODB CHARACTER SET utf8 COLLATE utf8_swedish_ci;
`
The text was updated successfully, but these errors were encountered: