diff --git a/lib/model.js b/lib/model.js index aaf5e29f..51a59397 100644 --- a/lib/model.js +++ b/lib/model.js @@ -158,10 +158,18 @@ ModelBaseClass.prototype._initProperties = function (data, options) { var def = properties[p]['default']; if (def !== undefined) { if (typeof def === 'function') { - self.__data[p] = def(); - } else { - self.__data[p] = def; + if (def === Date) { + // FIXME: We should coerce the value in general + // This is a work around to {default: Date} + // Date() will return a string instead of Date + def = new Date(); + } else { + def = def(); + } } + // FIXME: We should coerce the value + // will implement it after we refactor the PropertyDefinition + self.__data[p] = def; } } diff --git a/test/loopback-dl.test.js b/test/loopback-dl.test.js index d26647ce..3fa1ccd8 100644 --- a/test/loopback-dl.test.js +++ b/test/loopback-dl.test.js @@ -264,7 +264,7 @@ describe('DataSource define model', function () { name: String, bio: ModelBuilder.Text, approved: Boolean, - joinedAt: Date, + joinedAt: {type: Date, default: Date}, age: Number }); @@ -280,6 +280,8 @@ describe('DataSource define model', function () { assert.equal(user.name, 'Joe'); assert.equal(user.group, 'G1'); + assert(user.joinedAt instanceof Date); + // setup relationships User.hasMany(Post, {as: 'posts', foreignKey: 'userId'});