-
Notifications
You must be signed in to change notification settings - Fork 369
Closed
Labels
Description
Test example:
var TestEntity = db.define('testentity', {
name: {type: 'text', defaultValue: "Default name"},
rating: {type: 'number', rational: false, defaultValue: 0}
});
db.sync();
TestEntity.create([
{name: "Test name"},
{rating: 15},
{}
], function(err, items){
if(err){
throw err;
}
console.log("ok");
});$ node app.js
ok
mysql> SELECT * FROM testentity;
+----+-----------+--------+
| id | name | rating |
+----+-----------+--------+
| 1 | Test name | NULL |
| 2 | NULL | 15 |
| 3 | NULL | NULL |
+----+-----------+--------+
mysql> describe testentity;
+--------+------------------+------+-----+--------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+------------------+------+-----+--------------+----------------+
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(255) | YES | | Default name | |
| rating | int(11) | YES | | 0 | |
+--------+------------------+------+-----+--------------+----------------+
As you can see sync() works correctly and creates proper table structure containing default values. Therefore I assume that inserting query contains statement with explicit NULL assignement.
I think that orm should use default value if property of entity were not specified.
Reactions are currently unavailable