Work around for Date default
See https://github.com/strongloop/loopback-connector-postgresql/issues/15
This commit is contained in:
parent
332579ec87
commit
3edee5c4c5
14
lib/model.js
14
lib/model.js
|
@ -158,10 +158,18 @@ ModelBaseClass.prototype._initProperties = function (data, options) {
|
||||||
var def = properties[p]['default'];
|
var def = properties[p]['default'];
|
||||||
if (def !== undefined) {
|
if (def !== undefined) {
|
||||||
if (typeof def === 'function') {
|
if (typeof def === 'function') {
|
||||||
self.__data[p] = def();
|
if (def === Date) {
|
||||||
} else {
|
// FIXME: We should coerce the value in general
|
||||||
self.__data[p] = def;
|
// 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -264,7 +264,7 @@ describe('DataSource define model', function () {
|
||||||
name: String,
|
name: String,
|
||||||
bio: ModelBuilder.Text,
|
bio: ModelBuilder.Text,
|
||||||
approved: Boolean,
|
approved: Boolean,
|
||||||
joinedAt: Date,
|
joinedAt: {type: Date, default: Date},
|
||||||
age: Number
|
age: Number
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -280,6 +280,8 @@ describe('DataSource define model', function () {
|
||||||
assert.equal(user.name, 'Joe');
|
assert.equal(user.name, 'Joe');
|
||||||
assert.equal(user.group, 'G1');
|
assert.equal(user.group, 'G1');
|
||||||
|
|
||||||
|
assert(user.joinedAt instanceof Date);
|
||||||
|
|
||||||
// setup relationships
|
// setup relationships
|
||||||
User.hasMany(Post, {as: 'posts', foreignKey: 'userId'});
|
User.hasMany(Post, {as: 'posts', foreignKey: 'userId'});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue