Skip to content

Commit

Permalink
Merge pull request #39 from der-On/master
Browse files Browse the repository at this point in the history
various fixes to postgres adapter
  • Loading branch information
mde committed Apr 10, 2013
2 parents dcd94f8 + 41c8886 commit c4aa579
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lib/datatypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion lib/generators/sql.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

var model = require('../index')
, utils = require('utilities')
, generator
Expand All @@ -13,6 +12,8 @@ datatypeMap = {
, 'date': 'date'
, 'datetime': 'timestamp'
, 'time': 'time'
, 'object': 'text'
, 'array': 'text'
};

generator = new (function () {
Expand Down

3 comments on commit c4aa579

@der-On
Copy link
Contributor

@der-On der-On commented on c4aa579 Apr 27, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually where do we unserialize the JSON again? Saving it seems to work, however unserializing does not happen. This also leads to an invalid model as the 'object' properties now do not validate on a reloaded model that now has 'string' properties instead. This again leads to the result that one cannot save that invalid model.

@der-On
Copy link
Contributor

@der-On der-On commented on c4aa579 Apr 27, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For NoSQL adapters the object serialize should not be called or at least it should auto detect that it does not need to serialize the object.

@der-On
Copy link
Contributor

@der-On der-On commented on c4aa579 Apr 27, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a pull request about this: #53

Please sign in to comment.