Skip to content

fields I use custom name aren't inserted into database #41

Description

@outsideris

When I use custom field name, the fields are not inserted. Such like:

var User = schema.define('User', {
  lastLogin: { name: 'last_login', type: Date }
});

In lib/postgres.js:

PG.prototype.toFields = function (model, data, forCreate) {
    var fields = [];
    var props = this._models[model].properties;

    if(forCreate){
      var columns = [];
      Object.keys(data).forEach(function (key) {
          if (props[key]) {                 // I think problem is here!!
              if (key === 'id') return;
              columns.push('"' + key + '"');
              fields.push(this.toDatabase(props[key], data[key]));
          }
      }.bind(this));
      return '(' + columns.join(',') + ') VALUES ('+fields.join(',')+')';
    }else{
      Object.keys(data).forEach(function (key) {
          if (props[key]) {
              fields.push('"' + key + '" = ' + this.toDatabase(props[key], data[key]));
          }
      }.bind(this));
      return fields.join(',');
    }
};

In above function, props is:

{
  lastLogin: { name: 'last_login', type: [Function: Date] }
}

and Object.keys(data) is [ 'last_login' ]. So. props[key] is false and ignore the fields I use custom name.

I'm not sure this is handle in whether jugglingdb or postgres-adapter.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions