Coerce embedded model types
This commit is contained in:
parent
c19aca906d
commit
2b262c04f6
12
lib/model.js
12
lib/model.js
|
@ -175,7 +175,8 @@ ModelBaseClass.prototype._initProperties = function (data, options) {
|
|||
|
||||
// Handle complex types (JSON/Object)
|
||||
var type = properties[p].type;
|
||||
if (! BASE_TYPES[type.name]) {
|
||||
if (!BASE_TYPES[type.name]) {
|
||||
|
||||
if (typeof self.__data[p] !== 'object' && self.__data[p]) {
|
||||
try {
|
||||
self.__data[p] = JSON.parse(self.__data[p] + '');
|
||||
|
@ -183,7 +184,14 @@ ModelBaseClass.prototype._initProperties = function (data, options) {
|
|||
self.__data[p] = String(self.__data[p]);
|
||||
}
|
||||
}
|
||||
if (type.name === 'Array' || Array.isArray(type)) {
|
||||
|
||||
if (type.prototype instanceof ModelBaseClass) {
|
||||
if (!(self.__data[p] instanceof type)
|
||||
&& typeof self.__data[p] === 'object'
|
||||
&& self.__data[p] !== null ) {
|
||||
self.__data[p] = new type(self.__data[p]);
|
||||
}
|
||||
} else if (type.name === 'Array' || Array.isArray(type)) {
|
||||
if (!(self.__data[p] instanceof List)
|
||||
&& self.__data[p] !== undefined
|
||||
&& self.__data[p] !== null ) {
|
||||
|
|
Loading…
Reference in New Issue