scottwrobinson / camo

A class-based ES6 ODM for Mongo-like databases.
557 stars 81 forks source link

`that.collectionName is not a function` on EmbeddedDocument #26

Closed ijsf closed 8 years ago

ijsf commented 8 years ago

I am having an issue when trying to create (and save) an EmbeddedDocument. I have the following class:

class Reminder extends camo.EmbeddedDocument
{
  constructor()
  {
    super();
    this.enabled = { type: Boolean, required: true };
  }
}

Now, when I create a Reminder instance that does not adhere to the above, e.g. the enabled property is missing, like in this example:

Reminder.create({}).save();

I get the following error:

info: TypeError: that.collectionName is not a function

This is obviously an artifact of the new collectionName functionality in the validate function inside camo. Except, collectionName does not exist in EmbeddedDocument instances.

Probably quite an easy fix.

scottwrobinson commented 8 years ago

Yup, you're right. Dumb mistake, but an easy fix.

Also, just to be clear, make sure you're calling save() on the Document and not EmbeddedDocument object.

Should have the fix out soon with the rest of the bugs I'm working on. Thanks for pointing this out!

CKarper commented 8 years ago

+1