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

Date handling broken #21

Open
pmcnr-hx opened this issue Jan 13, 2016 · 1 comment
Open

Date handling broken #21

pmcnr-hx opened this issue Jan 13, 2016 · 1 comment
Labels

Comments

@pmcnr-hx
Copy link
Contributor

Properties declared in resources as Joi.date() are being persisted by the relationaldb store as strings but not being converted from the Date object that Joi returns, which results in the following error:

Rolling transaction back after error: {"name":"SequelizeValidationError","message":"string violation: birthDate cannot be an array or an object","errors":[{"message":"birthDate cannot be an array or an object","type":"string violation","path":"birthDate","value":"1969-12-31T16:00:00.000Z"}]} +6ms
Executing (917da062-51e8-4231-aec8-68bf5f19466c): ROLLBACK;
@theninj4 theninj4 added the bug label Apr 22, 2016
@heygrady
Copy link

I was just having a similar issue regarding the populate() method.

See lib/sqlHandler.js

SqlStore.prototype.populate = function(callback) {
  var self = this;

  var tasks = [
    function(cb) {
      self.baseModel.sync().asCallback(cb);
    },
    function(cb) {
      async.each(self.relationArray, function(model, ecb) {
        model.sync().asCallback(ecb);
      }, cb);
    },
    function(cb) {
      async.each(self.resourceConfig.examples, function(exampleJson, ecb) {
        var validation = Joi.validate(exampleJson, self.resourceConfig.attributes);
        if (validation.error) return ecb(validation.error);

        // Notice that validation.value has been altered by Joi
        // exampleJson was correctly validated, but validation.value was not
        // ironically the validated values aren't valid
        // you can get around this by using the exampleJson values

        // was: self.create({ request: { type: self.resourceConfig.resource } }, validation.value, ecb);

        // create re-validates the value for us
        self.create({ request: { type: self.resourceConfig.resource } }, exampleJson, ecb);
      }, cb);
    }
  ];

  async.series(tasks, callback);
};

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

No branches or pull requests

3 participants