Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
outsideris opened this issue May 18, 2014 · 2 comments
Open

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

outsideris opened this issue May 18, 2014 · 2 comments

Comments

@outsideris
Copy link

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.

@qfox
Copy link

qfox commented Jul 6, 2014

👍

@SashLi
Copy link

SashLi commented Dec 4, 2014

Same here. When running the manipulation testes it shows the same result. The "name" property is not used by the postgres-adapter (or is there something I missed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants