Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default values is not used when property is not specified #104

Closed
freemanrnd opened this issue Apr 8, 2013 · 2 comments
Closed

Default values is not used when property is not specified #104

freemanrnd opened this issue Apr 8, 2013 · 2 comments
Labels

Comments

@freemanrnd
Copy link

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.

@dresende
Copy link
Owner

dresende commented Apr 8, 2013

I'm going to test it, thank you

@dresende
Copy link
Owner

dresende commented Apr 8, 2013

Found it, posting fix in a minute.

dresende added a commit that referenced this issue Apr 8, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants