diff --git a/lib/datatypes.js b/lib/datatypes.js index 252e9021..f1d2b826 100644 --- a/lib/datatypes.js +++ b/lib/datatypes.js @@ -196,7 +196,7 @@ datatypes = { // Sure, Arrays are technically Objects, but we're treating Array as a // separate datatype. Remember, instanceof Array fails across window // boundaries, so let's also make sure the Object isn't Array-ish - if (typeof val != 'object' || _isArray(val)) { + if (typeof val != 'object'/* || _isArray(val)*/) { // by der_On: allow saving of arrays as the datatype array only saves arrays of numbers or strings correctly, but not arrays of objects return { err: i18n.getText('model.validatesObject', {name: name}, locale) , val: null @@ -210,8 +210,17 @@ datatypes = { , serialize: function (input, options) { var val , opts = options || {}; - if (typeof input.toString == 'function') { + + // Arrays will be converted to JSON + if (_isArray(input)) { + val = JSON.stringify(input); + } else if (typeof input.toString == 'function') { val = input.toString(); + + // if this happens the object had no usefull toString() method and we should make JSON out of it + if (val == "[object Object]") { + val = JSON.stringify(input); + } } else { val = JSON.stringify(input); diff --git a/lib/generators/sql.js b/lib/generators/sql.js index 8f2bedb9..d5d7cd95 100644 --- a/lib/generators/sql.js +++ b/lib/generators/sql.js @@ -1,4 +1,3 @@ - var model = require('../index') , utils = require('utilities') , generator @@ -13,6 +12,8 @@ datatypeMap = { , 'date': 'date' , 'datetime': 'timestamp' , 'time': 'time' +, 'object': 'text' +, 'array': 'text' }; generator = new (function () {