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

Schema hasn't been registered for model #71

Open
skarif2 opened this issue Oct 31, 2018 · 7 comments
Open

Schema hasn't been registered for model #71

skarif2 opened this issue Oct 31, 2018 · 7 comments

Comments

@skarif2
Copy link

skarif2 commented Oct 31, 2018

Fawn: 2.1.5 MongoDB: 3.6

Error: Schema hasn't been registered for model \"Promotion\".\nUse mongoose.model(name, schema)

My Code that is working:

promotion.save()
  .then((savedPromotion) => {
    const merchant = req.merchant;
    merchant.promotion = savedPromotion._id;
    return merchant.save();
  })
  .then(() => {
    res.json({
      status: 'success',
      message: 'Promotion successfully added.'
    });
  })
  .catch((err) => {
    res.json({
      status: 'error',
      message: err.message
    });
  });

Using Fawn which is not working:

const Task = Fawn.Task();
Task.save(Promotion, promotion)
  .update(Merchant, { _id: req.merchant._id }, {
    promotion: { $ojFuture: '0._id' }
  })
  .run({ useMongoose: true })
  .then(() => {
    res.json({
      status: 'success',
      message: 'Merchant promotion successfully added.'
    });
  })
  .catch((err) => {
    res.json({
      status: 'error',
      message: err.message
    });
  });

Both the model has reference to each other. I know circular reference is bad but couldn't find any other easier way. And I am being extra cautious while populating references.

So, am I missing something? Is there any workaround?

@e-oj
Copy link
Owner

e-oj commented Oct 31, 2018

Try

Task.save(promotion)

Instead of

Task.save(Promotion, promotion)

@skarif2
Copy link
Author

skarif2 commented Oct 31, 2018

Tried it. Getting the same error.

@e-oj
Copy link
Owner

e-oj commented Oct 31, 2018

Can you put up the code for the Promotion model?

@skarif2
Copy link
Author

skarif2 commented Oct 31, 2018

Promotion model: promotion.model.txt

BTW if I run bellow code and try to update only Merchant I get this error:

Error: Schema hasn't been registered for model \"Merchant\".\nUse mongoose.model(name, schema)

const Task = Fawn.Task();
Task
  // .save(Promotion, promotion)
  .update(Merchant, { _id: req.merchant._id }, {
    // promotion: { $ojFuture: '0._id' }
  })
  .run({ useMongoose: true })
  .then(() => {
    res.json({
      status: 'success',
      message: 'Merchant promotion successfully added.'
    });
  })
  .catch((err) => {
    res.json({
      status: 'error',
      message: err.message
    });
  });

@e-oj
Copy link
Owner

e-oj commented Nov 1, 2018

What version of Fawn are you using?

@skarif2
Copy link
Author

skarif2 commented Nov 1, 2018

Fawn: 2.1.5 MongoDB: 3.6

@e-oj
Copy link
Owner

e-oj commented Feb 3, 2019

It might be tied to the mongoose version #74

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

No branches or pull requests

2 participants