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

pre save middleware breaks promise support #40

Closed
bojand opened this issue Aug 24, 2016 · 1 comment
Closed

pre save middleware breaks promise support #40

bojand opened this issue Aug 24, 2016 · 1 comment
Labels

Comments

@bojand
Copy link
Contributor

bojand commented Aug 24, 2016

const schema = lounge.schema({
  title: String,
  metadata: {
    doctype: String,
    createdAt: Date,
    updatedAt: Date
  }
});

schema.pre('save', function(next) {
  if (!this.metadata) {
    this.metadata = {};
  }

  const now = new Date();

  if (!this.metadata.createdAt) {
    this.metadata.createdAt = now;
  }

  this.metadata.updatedAt = now;
  this.metadata.doctype = this.modelName.toLowerCase();

  next();
});

const Post = lounge.model('Post', schema);

const post = new Post({
  title: 'sample title'
});

const savedDoc = await post.save();
console.dir(savedDoc); // undefined

savedDoc is expected to be the saved document. Likely related to this issue in hooks-fixed and possibly this one since all of our generated instance models are inherit from a base class.

@bojand
Copy link
Contributor Author

bojand commented Sep 1, 2016

Fixed by #42

@bojand bojand closed this as completed Sep 1, 2016
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

1 participant